MRESULT EXPENTRY FontDlgProc( HWND hwndDlg, ULONG ulMsg, MPARAM mpParm1, MPARAM mpParm2 ) { HWND hwndWnd; switch ( ulMsg ) { case WM_HELP: DisplayHelpPanel( hwndDlg, IDP_OPTIONS_FONT_DLG ); return (MRESULT)FALSE; case WM_COMMAND: switch ( SHORT1FROMMP( mpParm1 ) ) { case DID_APPLY_BUTTON: hwndWnd = (HWND)fdFontDlg.ulUser; sprintf( achFont, "%d.%s", FIXEDINT( fdFontDlg.fxPointSize ), fdFontDlg.fAttrs.szFacename ); WinSetPresParam( hwndWnd, PP_FONTNAMESIZE, strlen( achFont ) + 1, achFont ); GetFontMetrics( hwndWnd, FALSE ); UpdateScreenLimits( hwndWnd, TRUE ); return (MRESULT)FALSE; default: return WinDefFontDlgProc( hwndDlg, ulMsg, mpParm1, mpParm2 ); } default: return WinDefFontDlgProc( hwndDlg, ulMsg, mpParm1, mpParm2 ); } }
void FontSelectDialog( HWND hwndWnd ) { /* * Bring up the font selection dialog; display only FIXED-pitch fonts! * Save the client window handle in the ulUser field. */ fdFontDlg.hpsScreen = WinGetPS( hwndWnd ); fdFontDlg.cbSize = sizeof( FONTDLG ); fdFontDlg.pszFamilyname = achFamily; fdFontDlg.usFamilyBufLen = sizeof( achFamily ); fdFontDlg.clrFore = CLR_BLACK; fdFontDlg.pszPreview = "AaBb"; fdFontDlg.fl = FNTS_CENTER | FNTS_FIXEDWIDTHONLY | FNTS_INITFROMFATTRS | FNTS_HELPBUTTON | FNTS_RESETBUTTON | FNTS_APPLYBUTTON; fdFontDlg.pfnDlgProc = FontDlgProc; fdFontDlg.ulUser = (ULONG)hwndWnd; WinFontDlg( HWND_DESKTOP, hwndWnd, (PFONTDLG)&fdFontDlg ); WinReleasePS( fdFontDlg.hpsScreen ); /* * If a font was successfully selected, copy its attributes into achFont and * use that to set the default PM font parameter for the client window. */ if ( fdFontDlg.lReturn == DID_OK ) { sprintf( achFont, "%d.%s", FIXEDINT( fdFontDlg.fxPointSize ), fdFontDlg.fAttrs.szFacename ); WinSetPresParam( hwndWnd, PP_FONTNAMESIZE, strlen( achFont ) + 1, achFont ); GetFontMetrics( hwndWnd, FALSE ); UpdateScreenLimits( hwndWnd, TRUE ); } }
static void PASCAL NewFont (HWND hDlg, BOOL TrustSizeEdit) /* setting TrustSizeEdit to FALSE indicates that the contents of the ID_FONTSIZE edit box should not be used (this is used when this function is called for a size list-selection change, at which time the edit box has not been updated yet) */ { DWORD d; int i; BOOL FontSizeOK; LOGFONT lf; HFONT hOldFont; hOldFont = hNewFont; i = SendDlgItemMessage (hDlg, ID_FONT, LB_GETCURSEL, 0, 0L); if (i == LB_ERR) lf.lfFaceName[0] = 0; else { SendDlgItemMessage (hDlg, ID_FONT, LB_GETTEXT, i, (DWORD)(LPSTR)lf.lfFaceName); } if (TrustSizeEdit) { i = GetDlgItemInt (hDlg, ID_FONTSIZE, &FontSizeOK, FALSE); } else FontSizeOK = FALSE; if (FontSizeOK) { lf.lfHeight = i; lf.lfWidth = 0; } else { i = SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_GETCURSEL, 0, 0L); if (i == CB_ERR) i = 0; d = SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_GETITEMDATA, i, 0L); lf.lfHeight = HIWORD(d); lf.lfWidth = LOWORD(d); } lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = IsDlgButtonChecked (hDlg, ID_BOLD) ? 700 : 400; lf.lfItalic = 0; lf.lfUnderline = 0; lf.lfStrikeOut = 0; lf.lfCharSet = IsDlgButtonChecked (hDlg, ID_ANSI) ? ANSI_CHARSET : OEM_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; hNewFont = CreateFontIndirect (&lf); GetFontMetrics (hNewFont, &Metrics, FaceName); UpdateMaxRowCol (hDlg, hNewFont); UpdateSample (hDlg, hNewFont, &Metrics, FaceName); if (hOldFont) DeleteObject (hOldFont); } /* NewFont */
static void PASCAL AddFace (HWND hDlg, char *CandidateFace) { BYTE CharSet; int From, At; /* indexes for list box searches */ HFONT hFixedFont; char FaceName [LF_FACESIZE]; TEXTMETRIC tm; CharSet = (IsDlgButtonChecked (hDlg, ID_ANSI) ? ANSI_CHARSET : OEM_CHARSET); /*-try to identify a fixed-pitch font of set CharSet, with the specified face name */ hFixedFont = CreateFont (0, 0, 0, 0, 0, FALSE, FALSE, FALSE, CharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FF_DONTCARE+FIXED_PITCH, CandidateFace); GetFontMetrics (hFixedFont, &tm, FaceName); DeleteObject (hFixedFont); if ((tm.tmPitchAndFamily & 0x01) || /* =1 if variable pitch */ (tm.tmCharSet != CharSet) || (strcmp (FaceName, CandidateFace) != 0)) { /* flunked the exam! */ return; /* skip that face */ } /* the candidate face has at least one fixed-pitch font with the right charset */ /*- scan the list box to make sure this face is not a duplicate */ At = -1; /* start at beginning of list box */ do { From = At; At = SendDlgItemMessage (hDlg, ID_FONT, LB_FINDSTRING, From, (DWORD)CandidateFace); if (At == LB_ERR) break; /* no match, implies not duplicate */ if (SendDlgItemMessage (hDlg, ID_FONT, LB_GETTEXTLEN, At, 0L) == strlen(CandidateFace)) { /* the lengths match, that means the strings match so it is indeed a duplicate */ return; } } while (At > From); /* exit if search has gone through the bottom of the list box */ /*-it is a brand new face, let's add it to the list */ SendDlgItemMessage (hDlg, ID_FONT, LB_ADDSTRING, 0, (DWORD)CandidateFace); return; } /* AddFace */
void CCustomPropSheet::BuildPropPageArray(void) { CDialogTemplate dlgtPageRes; __super::BuildPropPageArray(); // get first page CPropertyPage* pPage = GetPage(0); ASSERT(pPage != NULL); // load the dialog template VERIFY(dlgtPageRes.Load(pPage->m_psp.pszTemplate)); // get the font information // defaults CString strFaceName(_T("MS Shell Dlg 2")); WORD wPointSize = 8; if (!GetFontMetrics(strFaceName, wPointSize)) { // obtain from resource template VERIFY(dlgtPageRes.GetFont(strFaceName, wPointSize)); } if (m_fontPage.m_hObject != NULL) { VERIFY(m_fontPage.DeleteObject()); } // create a font using the info from first page LOGFONT lf = { 0 }; HDC hdcScreen = ::GetDC(NULL); ASSERT(hdcScreen != NULL); lf.lfHeight = ::MulDiv(-wPointSize, ::GetDeviceCaps(hdcScreen, LOGPIXELSY), 72); lf.lfWeight = FW_REGULAR; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = PROOF_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcsncpy(lf.lfFaceName, strFaceName, LF_FACESIZE - 1); VERIFY(m_fontPage.CreateFontIndirect(&lf)); ::ReleaseDC(NULL, hdcScreen); }
// Select a new character static VOID AddCharToSelection(HWND hDlg, WCHAR ch) { HWND hMap = GetDlgItem(hDlg, IDC_FONTMAP); HWND hText = GetDlgItem(hDlg, IDC_TEXTBOX); HFONT hFont; LOGFONT lFont; CHARFORMAT cf; // Retrieve current character selected if (ch == 0) { ch = (WCHAR) SendMessageW(hMap, FM_GETCHAR, 0, 0); if (!ch) return; } // Retrieve current selected font hFont = (HFONT)SendMessage(hMap, FM_GETHFONT, 0, 0); // Recover LOGFONT structure from hFont if (!GetObject(hFont, sizeof(LOGFONT), &lFont)) return; // Recover font properties of Richedit control ZeroMemory(&cf, sizeof(cf)); cf.cbSize = sizeof(cf); SendMessage(hText, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); // Apply properties of the new font cf.bCharSet = GetFontMetrics(hText, hFont); // Update font name wcscpy(cf.szFaceName, lFont.lfFaceName); // Update font properties SendMessage(hText, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); // Send selected character to Richedit SendMessage(hText, WM_CHAR, (WPARAM)ch, 0); }
void h2font_restore( HWND hwndWnd, HINI hiniPrf, PSZ pszApp ) { PrfQueryProfileString( hiniPrf, pszApp, szPrfKeyFont, szDefaultFont, achFont, sizeof( achFont ) ); WinSetPresParam( hwndWnd, PP_FONTNAMESIZE, strlen( achFont ) + 1, achFont ); GetFontMetrics( hwndWnd, TRUE ); }
void AwtMenuItem::MeasureSelf(HDC hDC, MEASUREITEMSTRUCT& measureInfo) { JNIEnv *env =(JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return; } /* self is a sun.awt.windows.WMenuItemPeer */ jobject self = GetPeer(env); /* font is a java.awt.Font */ jobject font = GetFont(env); jstring text = GetJavaString(env); SIZE size = AwtFont::getMFStringSize(hDC, font, text); /* 4700350: If the font size is taller than the menubar, change to the * default font. Otherwise, menu text is painted over the title bar and * client area. -bchristi */ if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) { jobject defFont = GetDefaultFont(env); env->DeleteLocalRef(font); font = env->NewLocalRef(defFont); size = AwtFont::getMFStringSize(hDC, font, text); } jstring fontName = (jstring)JNU_CallMethodByName(env, 0,font, "getName", "()Ljava/lang/String;").l; /* fontMetrics is a Hsun_awt_windows_WFontMetrics */ jobject fontMetrics = GetFontMetrics(env, font); // int height = env->GetIntField(fontMetrics, AwtFont::heightID); int height = (jint)JNU_CallMethodByName(env, 0, fontMetrics, "getHeight", "()I").i; measureInfo.itemHeight = height; measureInfo.itemHeight += measureInfo.itemHeight/3; // 3 is a heuristic number measureInfo.itemWidth = size.cx; if (!IsTopMenu()) { int checkWidth = ::GetSystemMetrics(SM_CXMENUCHECK); // Workaround for CR#6401956 if (IS_WINVISTA) { AdjustCheckWidth(checkWidth); } measureInfo.itemWidth += checkWidth; // Add in shortcut width, if one exists. jstring shortcutLabel = (jstring)env->GetObjectField(self, AwtMenuItem::shortcutLabelID); if (shortcutLabel != NULL) { size = AwtFont::getMFStringSize(hDC, font, shortcutLabel); measureInfo.itemWidth += size.cx + checkWidth; env->DeleteLocalRef(shortcutLabel); } } env->DeleteLocalRef(text); env->DeleteLocalRef(font); env->DeleteLocalRef(fontName); env->DeleteLocalRef(fontMetrics); }
/* =========== */ int EXPORT FAR PASCAL FontDlgProc (HWND hDlg, UINT wMsg, UINT wParam, LONG lParam) { switch (wMsg) { case WM_INITDIALOG: hNewFont = NULL; { /*-setup the dialog box's caption */ char s[40]; strcpy (s, ProgName); strcat (s, " - Font selection"); SetWindowText (hDlg, s); } /*-set the Bold button */ GetFontMetrics (hEmacsFont, &Metrics, FaceName); CheckDlgButton (hDlg, ID_BOLD, (Metrics.tmWeight > 550)); { /*-simulate a mouse click on the appropriate charset radiobutton. This will initialize all the other controls */ WORD id; id = (Metrics.tmCharSet == ANSI_CHARSET ? ID_ANSI : ID_OEM); SendMessage (hDlg, WM_COMMAND, #if WINDOW_MSWIN32 MAKELONG(id, BN_CLICKED), (long)GetDlgItem (hDlg, id)); #else id, MAKELONG(GetDlgItem (hDlg, id), BN_CLICKED)); #endif } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case 1: /* OK button */ if (NOTIFICATION_CODE == BN_CLICKED) { AcceptFont: if (hEmacsFont) DeleteObject (hEmacsFont); hEmacsFont = hNewFont; EndDialog (hDlg, TRUE); /* no need to unhook the SAMPLE's font, it is not destroyed since it will be used by emacs */ } else return FALSE; break; case 2: /* Cancel button */ if (NOTIFICATION_CODE == BN_CLICKED) goto CancelFont; else return FALSE; case ID_SAVEFONT: if (NOTIFICATION_CODE == BN_CLICKED) { /*-save the facename, bold status and size into WIN.INI, then perform as the OK button */ char NumText[17]; GetFontMetrics (hNewFont, &Metrics, FaceName); WriteProfileString (ProgName, "FontName", FaceName); WriteProfileString (ProgName, "CharSet", itoa (Metrics.tmCharSet, NumText, 10)); WriteProfileString (ProgName, "FontHeight", itoa (Metrics.tmHeight, NumText, 10)); WriteProfileString (ProgName, "FontWidth", itoa (Metrics.tmAveCharWidth, NumText, 10)); WriteProfileString (ProgName, "FontWeight", itoa (Metrics.tmWeight, NumText, 10)); } else return FALSE; goto AcceptFont; case ID_ANSI: case ID_OEM: if (NOTIFICATION_CODE == BN_CLICKED) { CheckRadioButton (hDlg, ID_1ST_CHARSET, ID_LAST_CHARSET, LOWORD(wParam)); BuildFaceList (hDlg, FaceName); } else return FALSE; break; case ID_BOLD: if (NOTIFICATION_CODE == BN_CLICKED) NewFont (hDlg, TRUE); else return FALSE; break; case ID_FONT: switch (NOTIFICATION_CODE) { case LBN_SELCHANGE: BuildSizeList (hDlg, &Metrics); break; case LBN_DBLCLK: /* treated as OK */ goto AcceptFont; default: return FALSE; } break; case ID_FONTSIZE: switch (NOTIFICATION_CODE) { case CBN_SELCHANGE: NewFont (hDlg, FALSE); break; case CBN_EDITCHANGE: { BOOL FontSizeOK; GetDlgItemInt (hDlg, ID_FONTSIZE, &FontSizeOK, FALSE); if (FontSizeOK) NewFont (hDlg, TRUE); else MessageBeep (0); } break; case CBN_DBLCLK: /* treated as OK */ goto AcceptFont; default: return FALSE; } break; default: return FALSE; } break; case WM_SYSCOMMAND: if ((wParam & 0xFFF0) == SC_CLOSE) { CancelFont: EndDialog (hDlg, FALSE); if (hNewFont) { SendDlgItemMessage (hDlg, ID_SAMPLE, WM_SETFONT, 0, FALSE); /* reset to SYSTEM_FONT before deleting the font */ DeleteObject (hNewFont); } return TRUE; } return FALSE; default: return FALSE; } return FALSE; } /* FontDlgProc */
/* ============= */ int EXPORT FAR PASCAL EnumSizesProc (LPLOGFONT lf, LPTEXTMETRIC tm, short FontType, LPSTR Data) /* Data should point to a handle to the dialog box */ { if ((lf->lfWeight > 400) || lf->lfItalic || lf->lfUnderline || lf->lfStrikeOut) return 1; #if WIN30SDK if (FontType & 0x04) { #else if (FontType & TRUETYPE_FONTTYPE) { #endif /* make a size list up */ short int h; for (h = lf->lfHeight / 4; h <= (3 * lf->lfHeight) / 2; h += 2) { AddSize (*(HWND FAR *)Data, h, 0); } return 0; /* no need to list this one further */ } else { /* non-scalable font */ /* list it only if it has a proper aspect ratio */ HFONT hFont; LOGFONT Font; TEXTMETRIC Metrics; Font = *lf; Font.lfWidth = 0; hFont = CreateFontIndirect (&Font); GetFontMetrics (hFont, &Metrics, NULL); DeleteObject (hFont); if (tm->tmAveCharWidth == Metrics.tmAveCharWidth) { AddSize (*(HWND FAR *)Data, (short int)lf->lfHeight, (short int)lf->lfWidth); } } return 1; } /* EnumSizesProc */ /* BuildSizeList: initializes the FontSize list box */ /* ============= */ static void PASCAL BuildSizeList (HWND hDlg, TEXTMETRIC *Metrics) /* This function initializes the FontSize list box with the sizes available for the face name currently selected in the Font list box. The sizes are written in the format: CXxCY. Also, the sizes are stored in the 32 bit values retrievable by LB_GETITEMDATA: width in the low-order word and height in the high order word */ { SendDlgItemMessage (hDlg, ID_FONTSIZE, WM_SETREDRAW, FALSE, 0L); SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_RESETCONTENT, 0, 0L); { HDC hDC; FARPROC ProcInstance; char FaceName[LF_FACESIZE]; SendDlgItemMessage (hDlg, ID_FONT, LB_GETTEXT, (UINT)SendDlgItemMessage (hDlg, ID_FONT, LB_GETCURSEL, 0, 0L), (DWORD)(LPSTR)&FaceName[0]); /* FaceName now contains the currently selected face name */ hDC = GetDC (hDlg); ProcInstance = MakeProcInstance ((FARPROC)EnumSizesProc, hEmacsInstance); EnumFonts (hDC, FaceName, ProcInstance, LPDATA(&hDlg)); FreeProcInstance (ProcInstance); ReleaseDC (hDlg, hDC); if (SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_GETCOUNT, 0, 0L) == 0) { /* no size at all in the size list (ATM, for instance, does that!). Let's fill it with a few sample sizes... */ short int h; for (h = 6; h <= 40; h += 2) AddSize (hDlg, h, 0); } } SendDlgItemMessage (hDlg, ID_FONTSIZE, WM_SETREDRAW, TRUE, 0L); InvalidateRect (GetDlgItem (hDlg, ID_FONTSIZE), NULL, TRUE); { /*-Select the larger height that is smaller or equal to the current Metrics (assumed to be the ones of the previous font) */ int i; int BestIndex = 0; short int h, w, BestHeight = 0, BestWidth = 0; DWORD ItemData; for (i = 0;; i++) { ItemData = SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_GETITEMDATA, i, 0L); if (ItemData == CB_ERR) break; /* end of list hit */ if ((h = HIWORD(ItemData)) > Metrics->tmHeight) continue; if (BestHeight > h) continue; w = LOWORD(ItemData); if (BestHeight == h) { /* use the width to optimize */ if (w > Metrics->tmAveCharWidth) continue; if (BestWidth > w) continue; } BestHeight = h; BestWidth = w; BestIndex = i; } SendDlgItemMessage (hDlg, ID_FONTSIZE, CB_SETCURSEL, BestIndex, 0L); } NewFont (hDlg, TRUE); } /* BuildSizeList */