static void winFontFromLogFontA(LOGFONTA* logfont, char* font) { int is_bold = (logfont->lfWeight == FW_NORMAL)? 0: 1; int is_italic = logfont->lfItalic; int is_underline = logfont->lfUnderline; int is_strikeout = logfont->lfStrikeOut; int height_pixels = logfont->lfHeight; /* negative value */ int res = iupwinGetScreenRes(); int size = iupWIN_PIXEL2PT(-height_pixels, res); /* return in points */ sprintf(font, "%s, %s%s%s%s %d", logfont->lfFaceName, is_bold?"Bold ":"", is_italic?"Italic ":"", is_underline?"Underline ":"", is_strikeout?"Strikeout ":"", size); }
void iupdrvToggleAddCheckBox(int *x, int *y, const char* str) { /* LAYOUT_DECORATION_ESTIMATE */ int check_box = 16; if (iupwinGetScreenRes() > 120) check_box = 26; (*x) += check_box; if ((*y) < check_box) (*y) = check_box; /* minimum height */ if (str && str[0]) /* add spacing between check box and text */ { (*x) += 8; if (!iupwin_comctl32ver6) (*x) += 4; } }
static IwinFont* winFindFont(const char *standardfont) { HFONT hFont; int height_pixels; /* negative value */ char typeface[50] = ""; int size = 8; int is_bold = 0, is_italic = 0, is_underline = 0, is_strikeout = 0; int res = iupwinGetScreenRes(); int i, count = iupArrayCount(win_fonts); const char* mapped_name; /* Check if the standardfont already exists in cache */ IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts); for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } if (!iupGetFontInfo(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; /* Map standard names to native names */ mapped_name = iupFontGetWinName(typeface); if (mapped_name) strcpy(typeface, mapped_name); /* get in pixels */ if (size < 0) height_pixels = size; /* already in pixels */ else height_pixels = -iupWIN_PT2PIXEL(size, res); if (height_pixels == 0) return NULL; hFont = CreateFont(height_pixels, 0,0,0, (is_bold) ? FW_BOLD : FW_NORMAL, is_italic, is_underline, is_strikeout, DEFAULT_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, FF_DONTCARE|DEFAULT_PITCH, iupwinStrToSystem(typeface)); if (!hFont) return NULL; /* create room in the array */ fonts = (IwinFont*)iupArrayInc(win_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].hFont = hFont; { HDC hdc = GetDC(NULL); HFONT oldfont = (HFONT)SelectObject(hdc, hFont); TEXTMETRIC tm; GetTextMetrics(hdc, &tm); /* NOTICE that this is different from CD. In IUP we need "average" width, in CD is "maximum" width. */ fonts[i].charwidth = tm.tmAveCharWidth; fonts[i].charheight = tm.tmHeight; SelectObject(hdc, oldfont); ReleaseDC(NULL, hdc); } return &fonts[i]; }
static int winFontDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); unsigned char r, g, b; CHOOSEFONT choosefont; LOGFONT logfont; char* standardfont; int height_pixels; char typeface[50] = ""; int height = 8; int is_bold = 0, is_italic = 0, is_underline = 0, is_strikeout = 0; int res = iupwinGetScreenRes(); iupAttribSetInt(ih, "_IUPDLG_X", x); iupAttribSetInt(ih, "_IUPDLG_Y", y); if (!parent) parent = GetActiveWindow(); standardfont = iupAttribGet(ih, "VALUE"); if (!standardfont) return IUP_ERROR; /* parse the old format first */ if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) return IUP_ERROR; } /* get size in pixels */ if (height < 0) height_pixels = height; /* already in pixels */ else height_pixels = -IUPWIN_PT2PIXEL(height, res); if (height_pixels == 0) return IUP_ERROR; ZeroMemory(&choosefont, sizeof(CHOOSEFONT)); choosefont.lStructSize = sizeof(CHOOSEFONT); if (iupStrToRGB(iupAttribGet(ih, "COLOR"), &r, &g, &b)) choosefont.rgbColors = RGB(r, g, b); choosefont.hwndOwner = parent; choosefont.lpLogFont = &logfont; choosefont.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_ENABLEHOOK; choosefont.lCustData = (LPARAM)ih; choosefont.lpfnHook = (LPCFHOOKPROC)winFontDlgHookProc; if (IupGetCallback(ih, "HELP_CB")) choosefont.Flags |= CF_SHOWHELP; strcpy(logfont.lfFaceName, typeface); logfont.lfHeight = height_pixels; logfont.lfWeight = (is_bold)? FW_BOLD: FW_NORMAL; logfont.lfItalic = (BYTE)is_italic; logfont.lfUnderline = (BYTE)is_underline; logfont.lfStrikeOut = (BYTE)is_strikeout; logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWidth = 0; logfont.lfOutPrecision = OUT_TT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = FF_DONTCARE|DEFAULT_PITCH; if (!ChooseFont(&choosefont)) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLOR", NULL); iupAttribSetStr(ih, "STATUS", NULL); return IUP_NOERROR; } is_bold = (logfont.lfWeight == FW_NORMAL)? 0: 1; is_italic = logfont.lfItalic; is_underline = logfont.lfUnderline; is_strikeout = logfont.lfStrikeOut; height_pixels = logfont.lfHeight; if (height < 0) /* not an error, use old value as reference of units */ height = height_pixels; /* return in pixels */ else height = IUPWIN_PIXEL2PT(-height_pixels, res); /* return in points */ iupAttribSetStrf(ih, "VALUE", "%s, %s%s%s%s %d", logfont.lfFaceName, is_bold?"Bold ":"", is_italic?"Italic ":"", is_underline?"Underline ":"", is_strikeout?"Strikeout ":"", height); iupAttribSetStrf(ih, "COLOR", "%d %d %d", GetRValue(choosefont.rgbColors), GetGValue(choosefont.rgbColors), GetBValue(choosefont.rgbColors)); iupAttribSetStr(ih, "STATUS", "1"); return IUP_NOERROR; }
static IwinFont* winFindFont(const char *standardfont) { HFONT hFont; int height_pixels; char typeface[50] = ""; int height = 8; int is_bold = 0, is_italic = 0, is_underline = 0, is_strikeout = 0; int res = iupwinGetScreenRes(); int i, count = iupArrayCount(win_fonts); const char* mapped_name; /* Check if the standardfont already exists in cache */ IwinFont* fonts = (IwinFont*)iupArrayGetData(win_fonts); for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* parse the old format first */ if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; } mapped_name = iupFontGetWinName(typeface); if (mapped_name) strcpy(typeface, mapped_name); /* get in pixels */ if (height < 0) height_pixels = height; /* already in pixels */ else height_pixels = -IUPWIN_PT2PIXEL(height, res); if (height_pixels == 0) return NULL; hFont = CreateFont(height_pixels, 0,0,0, (is_bold) ? FW_BOLD : FW_NORMAL, is_italic, is_underline, is_strikeout, DEFAULT_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, FF_DONTCARE|DEFAULT_PITCH, typeface); if (!hFont) return NULL; /* create room in the array */ fonts = (IwinFont*)iupArrayInc(win_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].hFont = hFont; { TEXTMETRIC tm; HDC hdc = GetDC(NULL); HFONT oldfont = SelectObject(hdc, hFont); GetTextMetrics(hdc, &tm); SelectObject(hdc, oldfont); ReleaseDC(NULL, hdc); fonts[i].charwidth = tm.tmAveCharWidth; fonts[i].charheight = tm.tmHeight; } return &fonts[i]; }