Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

印刷ページ設定ダイアログのフォントが巨大化する問題を修正 #1682

Conversation

suconbu
Copy link
Member

@suconbu suconbu commented May 24, 2021

PR の目的

本 PR では #1678 の「再現手順」の操作をした時に起きる以下の問題点を解消します。

  1. 印刷ページ設定ダイアログのフォントが巨大化する (印刷ページ設定ダイアログのフォントが巨大化してしまう #1678 で指摘されている現象)
  2. ヘッダー/フッター設定のフォント名の描画に、選択されたフォントが適用されていない
  3. ヘッダー/フッター設定のフォント名のサイズが大きすぎる (「1」により表面化していない)

カテゴリ

  • 不具合修正

PR の背景

目的に記載の通りです。

PR のメリット

不具合が解消されます。

PR のデメリット (トレードオフとかあれば)

特にありません。

仕様・動作説明

1. 印刷ページ設定ダイアログのフォントが巨大化する

CDialog::OnInitDialog における CDialog::m_hFontDialog の設定タイミングに問題があります。
SetData の先 (CDlgPrintSetting::SetFontName) で参照がされる可能性があったにも関わらず、現状はそれよりも後に初期化がされています。

BOOL CDialog::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
{
m_hWnd = hwndDlg;
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr( m_hWnd, DWLP_USER, lParam );
/* ダイアログデータの設定 */
SetData();
SetDialogPosSize();
m_hFontDialog = UpdateDialogFont( hwndDlg );
m_bInited = TRUE;
return TRUE;
}

対策内容:

  • CDialog::m_hFontDialog の初期化タイミングを CDialog::SetData よりも前に移動します。

2. ヘッダー/フッター設定のフォント名の描画に、選択されたフォントが適用されていない

CDialog::OnInitDialog における UpdateDialogFont の呼び出しタイミングに問題があります。
SetData の先 (CDlgPrintSetting::SetFontName) で STATIC コントロールに対して専用のフォントが設定される場合があるにも関わらず、その後、UpdateDialogFont -> SetFontRecursive が呼び出されることで、システムフォント相当のフォントで上書き設定されてしまっています。

対策内容:

  • UpdateDialogFont の呼び出しタイミングを CDialog::SetData よりも前に移動します。

3. ヘッダー/フッターのフォント名のサイズが大きすぎる

CDlgPrintSetting::OnInitDialog における CDlgPrintSetting::m_nFontHeight の設定タイミングに問題があります。
そのため CDlgPrintSetting::SetFontName (CDialog::OnInitDialog を経由して呼ばれる) におけるフォントハンドル作成時の高さ (LOGFONT::lfHeight) に 0 が指定されてしまいます。

BOOL bRet = CDialog::OnInitDialog( GetHwnd(), wParam, lParam );
// ダイアログフォントの寸法を得ておく
LOGFONT lf;
::GetObject(GetDialogFont(), sizeof(LOGFONT), &lf);
m_nFontHeight = lf.lfHeight; // フォントサイズ

lft.lfHeight = m_nFontHeight; // フォントサイズをダイアログに合せる
HFONT hFontOld = (HFONT)::SendMessage(GetItemHwnd( idTxt ), WM_GETFONT, 0, 0 );
// 論理フォントを作成
HFONT hFont = ::CreateFontIndirect( &lft );

対策内容:

  • CDlgPrintSetting::SetFontName でのフォント作成時に指定するサイズを、CDialog::GetDialogFont から得たフォントハンドルを元に取得するようにします。
  • それにより不要となる CDlgPrintSetting::m_nFontHeight を廃止します。(使用されていた場所は CDlgPrintSetting::SetFontName のみ)

PR の影響範囲

印刷ページ設定ダイアログの見た目に影響があります。

CDialog::m_hFontDialog の初期化タイミングが変化したことで、CDialog クラスを継承しているダイアログボックスのうち、CDialog::GetDialogFont() を呼び出しているものについて動作が変わる可能性がありますが、それに該当するクラスは CDlgPrintSetting のみでした。

テスト内容

※見た目の判断が必要なため手作業による確認を行います。

効果確認

弊害確認

  • 印刷ページ設定ダイアログ上のコントロールのサイズ/位置が変更前後で変化しないこと。(不具合発生しない手順で表示させた場合において)

関連 issue, PR

#1678
#1421

参考資料

@sonarcloud
Copy link

sonarcloud bot commented May 24, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

14.3% 14.3% Coverage
0.0% 0.0% Duplication

@AppVeyorBot
Copy link

Build sakura 1.0.3798 completed (commit b4b5c25606 by @suconbu)

@@ -185,13 +185,13 @@ BOOL CDialog::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr( m_hWnd, DWLP_USER, lParam );

m_hFontDialog = UpdateDialogFont( hwndDlg );

/* ダイアログデータの設定 */
SetData();

SetDialogPosSize();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行もSetData()の前に移動した方が良さそうです。
👆ダイアログの表示位置を調整する処理なので、描画を行う前のほうが良いはずです。

PR趣旨とは関係なさそうなのでスルーでいいです。

LOGFONT lfCreate = lf;
LOGFONT lfDialogFont = {};
::GetObject( GetDialogFont(), sizeof(LOGFONT), &lfDialogFont );
lfCreate.lfHeight = lfDialogFont.lfHeight;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは -abs(lfDialogFont.lfHeight) とかにしなくていいんでしたっけ?(自信ない

lfHeightに負数を指定すると対象フォントに指定サイズがなくても近似するサイズを選択してくれる、という仕様があった気がします(正数だと該当サイズがなければ失敗だったような。

自信ないのでコメントのみです。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは #1421 反映前のこの箇所と同じやり方としました。

m_hFontDlg = (HFONT)::SendMessage( GetHwnd(), WM_GETFONT, 0, 0 ); // ダイアログのフォント
LOGFONT lf;
::GetObject(m_hFontDlg, sizeof(LOGFONT), &lf);
m_nFontHeight = lf.lfHeight; // フォントサイズ

なお、
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfonta
こちらによると正/負どちらも近似サイズを選択するというのは共通していますが、

  • 正数の場合は「(character) cell height」 ("Â" 等の "^" が置かれる部分を含んだ高さ)
  • 負数の場合は「character height」("Â" 等の "^" の部分は除いた高さ)

ということでした。
正負が逆になると寸法が変わることを意味しますので、今回のケースではありのまま代入するのが正解のようです。

@suconbu
Copy link
Member Author

suconbu commented May 25, 2021

レビューありがとうございます。
動作確認で問題出なければこのままマージしてしまおうと思います。

@suconbu suconbu marked this pull request as ready for review May 25, 2021 15:28
@suconbu
Copy link
Member Author

suconbu commented May 25, 2021

無事動作確認が完了しましたのでマージします。

@suconbu suconbu merged commit f6912e3 into sakura-editor:master May 25, 2021
@beru beru added the 🐛bug🦋 ■バグ修正(Something isn't working) label Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug🦋 ■バグ修正(Something isn't working)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants