-
Notifications
You must be signed in to change notification settings - Fork 168
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
マウスホイールでのフォントサイズ変更をパーセンテージに基づいて行うようにする #1513
Changes from all commits
9c592ad
524b1cf
500abc5
d3a4f09
7d706d2
dbf47e2
3508ad0
54f30ba
33b2556
7cc9f00
45f601a
aa25ffa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ | |
#include "util/shell.h" | ||
#include "CPropertyManager.h" | ||
#include "util/window.h" | ||
#include "util/zoom.h" | ||
#include <array> | ||
|
||
|
||
/*! ツールバーの表示/非表示 | ||
|
||
|
@@ -251,18 +254,28 @@ void CViewCommander::Command_FONT( void ) | |
/*! フォントサイズ設定 | ||
@param fontSize フォントサイズ(1/10ポイント単位) | ||
@param shift フォントサイズを拡大or縮小するための変更量(fontSize=0のとき有効) | ||
@param mode フォントサイズ設定対象(0:フォント設定 1:タイプ別設定(なければ0と同じ) 2:一時適用フォント) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 既存設計なのでどうしようもないですが、マジックナンバーやめたいっす。 |
||
|
||
@note TrueTypeのみサポート | ||
|
||
@date 2013.04.10 novice 新規作成 | ||
*/ | ||
void CViewCommander::Command_SETFONTSIZE( int fontSize, int shift, int mode ) | ||
{ | ||
// The point sizes recommended by "The Windows Interface: An Application Design Guide", 1/10ポイント単位 | ||
static const INT sizeTable[] = { 8*10, 9*10, 10*10, (INT)(10.5*10), 11*10, 12*10, 14*10, 16*10, 18*10, 20*10, 22*10, 24*10, 26*10, 28*10, 36*10, 48*10, 72*10 }; | ||
// フォントサイズのズーム倍率テーブル | ||
constexpr std::array<double, 72> aZoomFactors = { | ||
0.01, 0.011, 0.0125, 0.015, 0.0175, 0.02, 0.0225, 0.025, 0.0275, 0.03, 0.035, 0.04, 0.045, 0.05, 0.06, 0.07, 0.08, 0.09, | ||
0.1, 0.11, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, | ||
1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0, 9.0, | ||
10.0, 11.0, 12.5, 15.0, 17.5, 20.0, 22.5, 25.0, 27.5, 30.0, 35.0, 40.0, 45.0, 50.0, 60.0, 70.0, 80.0, 90.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ところで、この定数値の根拠ってなんでしたっけ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 刻み方については #1491 (comment) で試作したものに近い変化率でかつ、パーセントで表示した時に切りの良い値としています。 |
||
}; | ||
// 設定できるフォントサイズの下限/上限/最小単位(いずれも1/10ポイント単位) | ||
constexpr int nPointSizeMin = 10; | ||
constexpr int nPointSizeMax = 720; | ||
constexpr int nPointSizeUnit = 5; | ||
berryzplus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static const ZoomSetting zoomSetting( aZoomFactors.begin(), aZoomFactors.end(), nPointSizeMin, nPointSizeMax, nPointSizeUnit ); | ||
const LOGFONT& lf = (mode == 0 ? GetDllShareData().m_Common.m_sView.m_lf | ||
: GetEditWindow()->GetLogfont( mode == 2 )); | ||
INT nPointSize; | ||
|
||
// TrueTypeのみ対応 | ||
if( OUT_STROKE_PRECIS != lf.lfOutPrecision && OUT_PS_ONLY_PRECIS != lf.lfOutPrecision ) { | ||
|
@@ -273,32 +286,26 @@ void CViewCommander::Command_SETFONTSIZE( int fontSize, int shift, int mode ) | |
return; | ||
} | ||
|
||
const int nOriginalPointSize = GetEditWindow()->GetFontPointSize( false ); | ||
double nCurrentZoom = (mode == 2 && GetDocument()->m_blfCurTemp) ? GetDocument()->m_nCurrentZoom : 1.0; | ||
int nPointSize; | ||
|
||
if( 0 != fontSize ){ | ||
// フォントサイズを直接選択する場合 | ||
nPointSize = t_max(sizeTable[0], t_min(sizeTable[_countof(sizeTable)-1], fontSize)); | ||
} else if( 0 != shift ) { | ||
nPointSize = std::clamp( fontSize, nPointSizeMin, nPointSizeMax ); | ||
berryzplus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nCurrentZoom = 1.0; | ||
}else if( 0 != shift ){ | ||
// 現在のフォントに対して、縮小or拡大したフォント選択する場合 | ||
nPointSize = (mode == 0 ? GetDllShareData().m_Common.m_sView.m_nPointSize | ||
: GetEditWindow()->GetFontPointSize( mode == 2 )); | ||
|
||
// フォントの拡大or縮小するためのサイズ検索 | ||
int i; | ||
for( i = 0; i < _countof(sizeTable); i++) { | ||
if( nPointSize <= sizeTable[i] ){ | ||
int index = t_max(0, t_min((int)_countof(sizeTable) - 1, (int)(i + shift))); | ||
int nNewPointSize = sizeTable[index]; | ||
// フォントサイズが変わらないので終了 | ||
if (nPointSize == nNewPointSize) { | ||
return; | ||
} | ||
nPointSize = nNewPointSize; | ||
break; | ||
} | ||
double nPointSizeF = 0.0; | ||
if( !GetZoomedValue( zoomSetting, nOriginalPointSize, nCurrentZoom, shift, &nPointSizeF, &nCurrentZoom ) ){ | ||
return; | ||
} | ||
} else { | ||
nPointSize = (int)nPointSizeF; | ||
}else{ | ||
// フォントサイズが変わらないので終了 | ||
berryzplus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
// 新しいフォントサイズ設定 | ||
int lfHeight = DpiPointsToPixels(-nPointSize, 10); | ||
int nTypeIndex = -1; | ||
|
@@ -324,7 +331,8 @@ void CViewCommander::Command_SETFONTSIZE( int fontSize, int shift, int mode ) | |
GetDocument()->m_lfCur = lf; | ||
GetDocument()->m_lfCur.lfHeight = lfHeight; | ||
GetDocument()->m_nPointSizeCur = nPointSize; | ||
GetDocument()->m_nPointSizeOrg = GetEditWindow()->GetFontPointSize(false); | ||
GetDocument()->m_nPointSizeOrg = nOriginalPointSize; | ||
GetDocument()->m_nCurrentZoom = nCurrentZoom; | ||
} | ||
|
||
HWND hwndFrame; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3409,7 +3409,8 @@ BEGIN | |
STR_ERR_DLGEDITVW6 "■" | ||
STR_MENU_KEYWORDINFO "キーワードの説明をクリップボードにコピー" | ||
STR_MENU_OPENKEYWORDDIC "キーワード辞書を開く" | ||
STR_STATUS_FONTSIZE "%4d %%" | ||
STR_STATUS_FONTZOOM_0 "%4.0f %%" | ||
STR_STATUS_FONTZOOM_1 "%4.1f %%" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 指摘じゃありませんが、結局残存してるのを確認。 |
||
STR_STATUS_ROW_COL "%5d 行 %4d 桁" | ||
STR_INS_MODE_INS "挿入" | ||
STR_INS_MODE_OVR "上書" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/*! @file | ||
@brief ズーム倍率算出 | ||
*/ | ||
/* | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
|
||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
|
||
1. The origin of this software must not be misrepresented; | ||
berryzplus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
|
||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
|
||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
|
||
#include "StdAfx.h" | ||
#include "zoom.h" | ||
#include <algorithm> | ||
#include <cmath> | ||
|
||
/*! | ||
@brief 値テーブル上における指定値の位置を取得 | ||
@param[in] vTable 値テーブル | ||
@param[in] nValue 指定値 | ||
@return 位置 | ||
@note 「位置」は基本的にはテーブルのインデックスに相当しますが、 | ||
テーブル範囲外およびテーブル上の隣り合う二値間については 0.5 で表現します。 | ||
@note 例として vTable:{10, 20, 30} の場合の nValue と戻り値との関係を示します。 | ||
nValue | 0 | 5 | 10 | 15 | 25 | 30 | 35 | 40 | | ||
-------|------|------|------|------|------|------|------|------| | ||
戻り値 | -0.5 | -0.5 | 0.0 | 0.5 | 1.5 | 2.0 | 2.5 | 2.5 | | ||
*/ | ||
[[nodiscard]] static double GetPositionInTable( const std::vector<double>& vTable, double nValue ) | ||
{ | ||
double nPosition = (double)vTable.size() - 0.5; | ||
for( size_t i = 0; i < vTable.size(); ++i ){ | ||
if( nValue <= vTable[i] ){ | ||
if( nValue == vTable[i] ){ | ||
nPosition = (double)i; | ||
}else{ | ||
nPosition = (double)i - 0.5; | ||
} | ||
break; | ||
} | ||
} | ||
return nPosition; | ||
} | ||
|
||
/*! | ||
@brief 最小単位で丸めた値を取得 | ||
@param[in] nValue 対象値 | ||
@param[in] nUnit 最小単位(0.0 の場合は丸めなし) | ||
@return 丸められた値 | ||
*/ | ||
[[nodiscard]] static double GetQuantizedValue( double nValue, double nUnit ) | ||
{ | ||
return (0.0 < nUnit) ? std::floor( nValue / nUnit ) * nUnit : nValue; | ||
} | ||
|
||
/*! | ||
@brief 拡大方向の移動量を反映したズーム倍率テーブルのインデックスを取得 | ||
@param[in] zoomSetting ズーム設定 | ||
@param[in] nBaseValue 基準値 | ||
@param[in] nCurrentValue 現在値 | ||
@param[in] nCurrentIndex 現在値に対応するインデックス | ||
@param[in] nUpSteps インデックスの移動量(1以上であること) | ||
@return ズーム倍率テーブルのインデックス | ||
*/ | ||
[[nodiscard]] static int GetZoomUpIndex( const ZoomSetting& zoomSetting, double nBaseValue, double nCurrentValue, int nCurrentIndex, int nUpSteps ) | ||
{ | ||
int nIndex = nCurrentIndex + nUpSteps; | ||
const int nIndexMax = (int)zoomSetting.m_vZoomFactors.size() - 1; | ||
for( ; nIndex < nIndexMax; ++nIndex ){ | ||
double nNextValue = nBaseValue * zoomSetting.m_vZoomFactors[nIndex]; | ||
nNextValue = GetQuantizedValue( nNextValue, zoomSetting.m_nValueUnit ); | ||
if( nNextValue != nCurrentValue ){ | ||
break; | ||
} | ||
} | ||
|
||
return std::min( nIndex, nIndexMax ); | ||
} | ||
|
||
/*! | ||
@brief 縮小方向の移動量を反映したズーム倍率テーブルのインデックスを取得 | ||
@param[in] zoomSetting ズーム設定 | ||
@param[in] nBaseValue 基準値 | ||
@param[in] nCurrentValue 現在値 | ||
@param[in] nCurrentIndex 現在値に対応するインデックス | ||
@param[in] nDownSteps インデックスの移動量(1以上であること) | ||
@return ズーム倍率テーブルのインデックス | ||
*/ | ||
[[nodiscard]] static int GetZoomDownIndex( const ZoomSetting& zoomSetting, double nBaseValue, double nCurrentValue, int nCurrentIndex, int nDownSteps ) | ||
{ | ||
int nIndex = nCurrentIndex - nDownSteps; | ||
double nLastValue = nCurrentValue; | ||
bool bFindingOneMoreChange = false; | ||
for( ; 0 <= nIndex; --nIndex ){ | ||
double nValue = nBaseValue * zoomSetting.m_vZoomFactors[nIndex]; | ||
nValue = GetQuantizedValue( nValue, zoomSetting.m_nValueUnit ); | ||
if( bFindingOneMoreChange && nValue != nLastValue ){ | ||
break; | ||
}else if( nValue != nCurrentValue ){ | ||
// もう一度値が変化するまでインデックスを進める | ||
bFindingOneMoreChange = true; | ||
kengoide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nLastValue = nValue; | ||
}else{ | ||
// 値が変化しなかったので次へ | ||
} | ||
} | ||
|
||
if( bFindingOneMoreChange ){ | ||
++nIndex; | ||
} | ||
|
||
return std::max( 0, nIndex ); | ||
} | ||
|
||
/*! | ||
@brief 基準値に対してズーム倍率を適用した値を取得 | ||
@param[in] zoomSetting ズーム設定 | ||
@param[in] nBaseValue 基準値 | ||
@param[in] nCurrentZoom 変更前のズーム倍率 | ||
@param[in] nSteps ズーム段階の変更量 | ||
@param[out] pnValueOut 変更後のズーム倍率を適用した値 | ||
@param[out] pnZoomOut 変更後のズーム倍率 | ||
@return ズームできたかどうか | ||
@note 戻り値が false の場合には pnValueOut, pnZoomOut は設定されません。 | ||
*/ | ||
bool GetZoomedValue( const ZoomSetting& zoomSetting, double nBaseValue, double nCurrentZoom, int nSteps, double* pnValueOut, double* pnZoomOut ) | ||
{ | ||
if( nSteps == 0 ){ | ||
return false; | ||
} | ||
|
||
const bool bZoomUp = (0 < nSteps); | ||
const int nIndexMin = 0; | ||
const int nIndexMax = (int)zoomSetting.m_vZoomFactors.size() - 1; | ||
|
||
const double nPosition = GetPositionInTable( zoomSetting.m_vZoomFactors, nCurrentZoom ); | ||
auto nCurrentIndex = (int)(bZoomUp ? std::floor( nPosition ) : std::ceil( nPosition )); | ||
if( (!bZoomUp && nCurrentIndex <= nIndexMin) || (bZoomUp && nIndexMax <= nCurrentIndex) ){ | ||
// 現在の倍率がすでに倍率テーブルの範囲外でかつ | ||
// さらに外側へ移動しようとした場合は今の位置を維持 | ||
return false; | ||
} | ||
|
||
const double nCurrentValue = GetQuantizedValue( nBaseValue * nCurrentZoom, zoomSetting.m_nValueUnit ); | ||
const double nValueMin = std::min( {zoomSetting.m_nValueMin, nBaseValue, nCurrentValue} ); | ||
const double nValueMax = std::max( {zoomSetting.m_nValueMax, nBaseValue, nCurrentValue} ); | ||
|
||
int nNextIndex; | ||
if( bZoomUp ){ | ||
nNextIndex = GetZoomUpIndex( zoomSetting, nBaseValue, nCurrentValue, nCurrentIndex, nSteps ); | ||
}else{ | ||
nNextIndex = GetZoomDownIndex( zoomSetting, nBaseValue, nCurrentValue, nCurrentIndex, -nSteps ); | ||
} | ||
double nNextZoom = zoomSetting.m_vZoomFactors[nNextIndex]; | ||
double nNextValue = GetQuantizedValue( nBaseValue * nNextZoom, zoomSetting.m_nValueUnit ); | ||
|
||
if( nNextValue < nValueMin || nValueMax < nNextValue ){ | ||
// 値の上下限を超過していたら上下限で丸める | ||
// 倍率は丸めた後のサイズで再計算 | ||
nNextValue = std::clamp( nNextValue, nValueMin, nValueMax ); | ||
if( nBaseValue != 0.0 ){ | ||
nNextZoom = nNextValue / nBaseValue; | ||
} | ||
} | ||
|
||
if( nCurrentValue == nNextValue ){ | ||
return false; | ||
} | ||
|
||
if( pnValueOut != nullptr ){ | ||
*pnValueOut = nNextValue; | ||
} | ||
if( pnZoomOut != nullptr ){ | ||
*pnZoomOut = nNextZoom; | ||
} | ||
|
||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ファイル末尾の行末改行、「無し」から「有り」に変更。
スルーしますけど戻してもスルーする気がします。