Browse Source

updated how i scale the font, save unscaled font

sabrogden 6 years ago
parent
commit
3476cc55bb
4 changed files with 20 additions and 25 deletions
  1. 2 1
      AdvGeneral.cpp
  2. 5 3
      DPI.h
  3. 12 20
      OptionsGeneral.cpp
  4. 1 1
      QListCtrl.cpp

+ 2 - 1
AdvGeneral.cpp

@@ -146,7 +146,8 @@ BOOL CAdvGeneral::OnInitDialog()
 
 
 	HDITEM hdItem;
 	HDITEM hdItem;
 	hdItem.mask = HDI_WIDTH; // indicating cxy is width
 	hdItem.mask = HDI_WIDTH; // indicating cxy is width
-	hdItem.cxy = 325; // whatever you want the property name column width to be
+	CDPI dpi(m_hWnd);
+	hdItem.cxy = dpi.Scale(325); // whatever you want the property name column width to be
 	m_propertyGrid.GetHeaderCtrl().SetItem(0, &hdItem);
 	m_propertyGrid.GetHeaderCtrl().SetItem(0, &hdItem);
 
 
 	m_propertyGrid.SetFont(this->GetFont());	
 	m_propertyGrid.SetFont(this->GetFont());	

+ 5 - 3
DPI.h

@@ -3,8 +3,9 @@
 class CDPI
 class CDPI
 {
 {
 public:
 public:
-	CDPI() : _fInitialized(false), m_dpi(96)
-	{ 
+	CDPI(HWND hwnd = NULL) : _fInitialized(false), m_dpi(96)
+	{
+		m_hWnd = hwnd;
 	}
 	}
 
 
 	void Update(int dpi) { m_dpi = dpi;  _fInitialized = true; }
 	void Update(int dpi) { m_dpi = dpi;  _fInitialized = true; }
@@ -24,7 +25,7 @@ private:
 	{
 	{
 		if (!_fInitialized)
 		if (!_fInitialized)
 		{
 		{
-			HDC hdc = GetDC(NULL);
+			HDC hdc = GetDC(m_hWnd);
 			if (hdc)
 			if (hdc)
 			{
 			{
 				m_dpi = GetDeviceCaps(hdc, LOGPIXELSX);
 				m_dpi = GetDeviceCaps(hdc, LOGPIXELSX);
@@ -37,4 +38,5 @@ private:
 private:
 private:
 	bool _fInitialized;
 	bool _fInitialized;
 	int m_dpi;
 	int m_dpi;
+	HWND m_hWnd;
 };
 };

+ 12 - 20
OptionsGeneral.cpp

@@ -559,7 +559,6 @@ void COptionsGeneral::OnBnClickedButtonTheme()
 
 
 void COptionsGeneral::OnBnClickedButtonDefaultFault()
 void COptionsGeneral::OnBnClickedButtonDefaultFault()
 {
 {
-
 	memset(&m_LogFont, 0, sizeof(m_LogFont));
 	memset(&m_LogFont, 0, sizeof(m_LogFont));
 
 
 	m_LogFont.lfHeight = -13;
 	m_LogFont.lfHeight = -13;
@@ -574,34 +573,27 @@ void COptionsGeneral::OnBnClickedButtonDefaultFault()
 
 
 int COptionsGeneral::GetFontSize(HWND hWnd, const LOGFONT& lf)
 int COptionsGeneral::GetFontSize(HWND hWnd, const LOGFONT& lf)
 {
 {
-	int nFontSize = 0;
-
-	HDC hDC = ::GetWindowDC(hWnd);
-
-	if (lf.lfHeight < 0)
-	{
-		nFontSize = -::MulDiv(lf.lfHeight, 72, ::GetDeviceCaps(hDC, LOGPIXELSY));
-	}
-	else
-	{
-		TEXTMETRIC tm;
-		::ZeroMemory(&tm, sizeof(TEXTMETRIC));
-		::GetTextMetrics(hDC, &tm);
-
-		nFontSize = ::MulDiv(lf.lfHeight - tm.tmInternalLeading, 72, ::GetDeviceCaps(hDC, LOGPIXELSY));
-	}
-	::ReleaseDC(hWnd, hDC);
-
+	//font is saved un scaled, so scale it with the default values to get the font size
+	int nFontSize = -::MulDiv(lf.lfHeight, 72, 96);
+	
 	return nFontSize;
 	return nFontSize;
 }
 }
 
 
 void COptionsGeneral::OnBnClickedButtonFont()
 void COptionsGeneral::OnBnClickedButtonFont()
 {
 {
+	CDPI d(m_hWnd);
+
+	//scale it back up so the font dialog shows the correct value
+	m_LogFont.lfHeight = d.Scale(m_LogFont.lfHeight);
+
 	CFontDialog dlg(&m_LogFont, (CF_TTONLY | CF_SCREENFONTS), 0, this);
 	CFontDialog dlg(&m_LogFont, (CF_TTONLY | CF_SCREENFONTS), 0, this);
 	if (dlg.DoModal() == IDOK)
 	if (dlg.DoModal() == IDOK)
 	{
 	{
 		memcpy(&m_LogFont, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
 		memcpy(&m_LogFont, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
-				
+		
+		//save the font unscaled, we will scale it as needed when we what to use it
+		m_LogFont.lfHeight = d.UnScale(m_LogFont.lfHeight);
+
 		CString cs;
 		CString cs;
 		cs.Format(_T("Font - %s (%d)"), m_LogFont.lfFaceName, GetFontSize(m_hWnd, m_LogFont));
 		cs.Format(_T("Font - %s (%d)"), m_LogFont.lfFaceName, GetFontSize(m_hWnd, m_LogFont));
 		m_btFont.SetWindowText(cs);
 		m_btFont.SetWindowText(cs);

+ 1 - 1
QListCtrl.cpp

@@ -1629,7 +1629,7 @@ void CQListCtrl::CreateSmallFont()
 {
 {
 	LOGFONT lf;
 	LOGFONT lf;
 
 
-	lf.lfHeight = m_windowDpi->Scale(-MulDiv(g_Opt.GetFirstTenHotKeysFontSize(), GetDeviceCaps(::GetDC(NULL), LOGPIXELSY), 72));
+	lf.lfHeight = -MulDiv(g_Opt.GetFirstTenHotKeysFontSize(), GetDeviceCaps(::GetDC(m_hWnd), LOGPIXELSY), 72);
 	lf.lfWidth = 0;
 	lf.lfWidth = 0;
 	lf.lfEscapement = 0;
 	lf.lfEscapement = 0;
 	lf.lfOrientation = 0;
 	lf.lfOrientation = 0;