/* * Discard all of the font information, e.g., we are resizing the font. * Keep the GC's so we can simply change them rather than creating new ones. */ void clrCgsFonts(XtermWidget xw, VTwin *cgsWin, XTermFonts * font) { CgsCache *me; int j, k; if (HaveFont(font)) { for_each_gc(j) { if ((me = myCache(xw, cgsWin, (CgsEnum) j)) != 0) { for (k = 0; k < DEPTH; ++k) { if (SameFont(LIST(k).font, font)) { TRACE2(("clrCgsFonts %s gc %p(%d) %s\n", traceCgsEnum((CgsEnum) j), LIST(k).gc, k, traceFont(font))); LIST(k).font = 0; LIST(k).cset = 0; } } if (SameFont(NEXT(font), font)) { TRACE2(("clrCgsFonts %s next %s\n", traceCgsEnum((CgsEnum) j), traceFont(font))); NEXT(font) = 0; NEXT(cset) = 0; me->mask &= (unsigned) ~(GCFont | GC_CSet); } } } } }
BOOL GraphicsMisc::SameFontNameSize(HFONT hFont1, HFONT hFont2) { CString sName1; int nSize1 = GetFontNameAndPointSize(hFont1, sName1); return SameFont(hFont2, sName1, nSize1); }
HFONT GraphicsMisc::CreateFont(LPCTSTR szFaceName, int nPoint, DWORD dwFlags) { HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); ASSERT (hDefFont); LOGFONT lf; ::GetObject(hDefFont, sizeof(lf), &lf); // set the charset if (dwFlags & GMFS_SYMBOL) { lf.lfCharSet = SYMBOL_CHARSET; } else if (!lf.lfCharSet) { lf.lfCharSet = DEFAULT_CHARSET; } if (szFaceName && *szFaceName) { lstrcpy(lf.lfFaceName, szFaceName); // reset character-set lf.lfCharSet = DEFAULT_CHARSET; } if (nPoint > 0) { lf.lfHeight = -PointToPixel(nPoint); } else if (dwFlags & GMFS_SYMBOL) { lf.lfHeight = MulDiv(lf.lfHeight, 12, 10); } lf.lfWidth = 0; lf.lfUnderline = (BYTE)(dwFlags & GMFS_UNDERLINED); lf.lfItalic = (BYTE)(dwFlags & GMFS_ITALIC); lf.lfStrikeOut = (BYTE)(dwFlags & GMFS_STRIKETHRU); lf.lfWeight = (dwFlags & GMFS_BOLD) ? FW_BOLD : FW_NORMAL; HFONT hFont = CreateFontIndirect(&lf); // verify the font creation if (!SameFont(hFont, szFaceName, nPoint)) { VerifyDeleteObject(hFont); hFont = NULL; } return hFont; }
static GC chgCache(XtermWidget xw, CgsEnum cgsId GCC_UNUSED, CgsCache * me, Bool both) { XGCValues xgcv; XtGCMask mask = (GCForeground | GCBackground | GCFont); memset(&xgcv, 0, sizeof(xgcv)); TRACE2(("chgCache(%s) old data fg=%s, bg=%s, font=%s cset %s\n", traceCgsEnum(cgsId), tracePixel(xw, THIS(fg)), tracePixel(xw, THIS(bg)), traceFont(THIS(font)), traceCSet(THIS(cset)))); #if OPT_TRACE > 1 if (!SameFont(THIS(font), NEXT(font))) TRACE2(("...chgCache new font=%s\n", traceFont(NEXT(font)))); if (!SameCSet(THIS(cset), NEXT(cset))) TRACE2(("...chgCache new cset=%s\n", traceCSet(NEXT(cset)))); if (!SameColor(THIS(fg), NEXT(fg))) TRACE2(("...chgCache new fg=%s\n", tracePixel(xw, NEXT(fg)))); if (!SameColor(THIS(bg), NEXT(bg))) TRACE2(("...chgCache new bg=%s\n", tracePixel(xw, NEXT(bg)))); #endif if (both) { THIS(font) = NEXT(font); THIS(cset) = NEXT(cset); } THIS(fg) = NEXT(fg); THIS(bg) = NEXT(bg); xgcv.font = THIS(font)->fs->fid; xgcv.foreground = THIS(fg); xgcv.background = THIS(bg); XChangeGC(myDisplay(xw), THIS(gc), mask, &xgcv); TRACE2(("...chgCache(%s) updated gc %p(%d)\n", traceCgsEnum(cgsId), THIS(gc), ITEM())); THIS(used) = 0; return THIS(gc); }
/* * Return a GC associated with the given id, allocating if needed. */ GC getCgsGC(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId) { CgsCache *me; GC result = 0; int j, k; unsigned used = 0; if ((me = myCache(xw, cgsWin, cgsId)) != 0) { TRACE2(("getCgsGC(%s, %s)\n", traceVTwin(xw, cgsWin), traceCgsEnum(cgsId))); if (me->mask != 0) { /* fill in the unchanged fields */ if (!(me->mask & GC_CSet)) NEXT(cset) = 0; /* OPT_DEC_CHRSET */ if (!(me->mask & GCFont)) NEXT(font) = THIS(font); if (!(me->mask & GCForeground)) NEXT(fg) = THIS(fg); if (!(me->mask & GCBackground)) NEXT(bg) = THIS(bg); if (NEXT(font) == 0) { setCgsFont(xw, cgsWin, cgsId, 0); } TRACE2(("...Cgs new data fg=%s, bg=%s, font=%s cset %s\n", tracePixel(xw, NEXT(fg)), tracePixel(xw, NEXT(bg)), traceFont(NEXT(font)), traceCSet(NEXT(cset)))); /* try to find the given data in an already-created GC */ for (j = 0; j < DEPTH; ++j) { if (LIST(j).gc != 0 && SameFont(LIST(j).font, NEXT(font)) && SameCSet(LIST(j).cset, NEXT(cset)) && SameColor(LIST(j).fg, NEXT(fg)) && SameColor(LIST(j).bg, NEXT(bg))) { LINK(j); result = THIS(gc); TRACE2(("getCgsGC existing %p(%d)\n", result, ITEM())); break; } } if (result == 0) { /* try to find an empty slot, to create a new GC */ used = 0; for (j = 0; j < DEPTH; ++j) { if (LIST(j).gc == 0) { LINK(j); result = newCache(xw, cgsWin, cgsId, me); break; } if (used < LIST(j).used) used = LIST(j).used; } } if (result == 0) { /* if none were empty, pick the least-used slot, to modify */ for (j = 0, k = -1; j < DEPTH; ++j) { if (used >= LIST(j).used) { used = LIST(j).used; k = j; } } LINK(k); TRACE2(("...getCgsGC least-used(%d) was %d\n", k, THIS(used))); result = chgCache(xw, cgsId, me, True); } me->next = *(me->data); } else { result = THIS(gc); } me->mask = 0; THIS(used) += 1; TRACE2(("...getCgsGC(%s, %s) gc %p(%d), used %d\n", traceVTwin(xw, cgsWin), traceCgsEnum(cgsId), result, ITEM(), THIS(used))); } return result; }