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

テキスト幅計算に使用する文字間隔配列のコンテナを使いまわす事で負荷を削減 #1415

Merged
merged 1 commit into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sakura_core/print/CPrintPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,8 @@ void CPrintPreview::DrawHeaderFooter( HDC hdc, const CMyRect& rect, bool bHeader
bHeader ? m_pPrintSetting->m_szHeaderForm[POS_CENTER] : m_pPrintSetting->m_szFooterForm[POS_CENTER],
szWork, nWorkLen);
nLen = wcslen( szWork );
nTextWidth = CTextMetrics::CalcTextWidth2(szWork, nLen, nDx, spaceing); //テキスト幅
std::vector<int> vDxArray;
nTextWidth = CTextMetrics::CalcTextWidth2(szWork, nLen, nDx, spaceing, vDxArray); //テキスト幅
Print_DrawLine(
hdc,
CMyPoint(
Expand All @@ -1366,7 +1367,7 @@ void CPrintPreview::DrawHeaderFooter( HDC hdc, const CMyRect& rect, bool bHeader
bHeader ? m_pPrintSetting->m_szHeaderForm[POS_RIGHT] : m_pPrintSetting->m_szFooterForm[POS_RIGHT],
szWork, nWorkLen);
nLen = wcslen( szWork );
nTextWidth = CTextMetrics::CalcTextWidth2(szWork, nLen, nDx, spaceing); //テキスト幅
nTextWidth = CTextMetrics::CalcTextWidth2(szWork, nLen, nDx, spaceing, vDxArray); //テキスト幅
Print_DrawLine(
hdc,
CMyPoint(
Expand Down
9 changes: 4 additions & 5 deletions sakura_core/view/CTextMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ int CTextMetrics::CalcTextWidth2(
const wchar_t* pText, //!< 文字列
int nLength, //!< 文字列長
int nHankakuDx, //!< 半角文字の文字間隔
int nCharSpacing //!< 文字の隙間
int nCharSpacing, //!< 文字の隙間
std::vector<int>& vDxArray //!< [out] 文字間隔配列
)
{
//文字間隔配列を生成
vector<int> vDxArray;
const int* pDxArray = CTextMetrics::GenerateDxArray(
&vDxArray,
pText,
Expand All @@ -258,8 +257,8 @@ int CTextMetrics::CalcTextWidth2(

int CTextMetrics::CalcTextWidth3(
const wchar_t* pText, //!< 文字列
int nLength //!< 文字列長
int nLength //!< 文字列長
Copy link
Contributor

Choose a reason for hiding this comment

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

影響ないと思うのでスルーします。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ついでにインデントの調整を行いました。

) const
{
return CalcTextWidth2(pText, nLength, GetCharPxWidth(), GetCharSpacing());
return CalcTextWidth2(pText, nLength, GetCharPxWidth(), GetCharSpacing(), m_vDxArray);
}
4 changes: 3 additions & 1 deletion sakura_core/view/CTextMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class CTextMetrics{
const wchar_t* pText, //!< 文字列
int nLength, //!< 文字列長
int nHankakuDx, //!< 半角文字の文字間隔
int nCharSpacing
int nCharSpacing, //!< 文字の隙間
std::vector<int>& vDxArray //!< [out] 文字間隔配列
Copy link
Contributor

Choose a reason for hiding this comment

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

100%好みに基づく変更要望ですが、std::vector<INT>がいいです。

根拠は windows api の型定義で、DxArrayの型定義は本来 const INT* だからです。
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-exttextoutw

あとになってグダグダ言うのは嫌なのでいまのうちに指摘しときますが、元定義が vector<int> やんけ!というのももっともだと思うのでこのままでもいいっす。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確かにそうした方が好ましいですが将来的に問題になる事はおそらく無いと思います。
Microsoft Win64 のデータモデルが LLP64 なので。

);

int CalcTextWidth3(
Expand All @@ -129,5 +130,6 @@ class CTextMetrics{
int m_anHankakuDx[64]; //!< 半角用文字間隔配列
int m_anZenkakuDx[64]; //!< 全角用文字間隔配列
std::vector<int> m_aFontHeightMargin;
mutable std::vector<int> m_vDxArray; //!< 文字間隔配列
};
#endif /* SAKURA_CTEXTMETRICS_7972A864_FDFF_4852_9EA5_A91D39657A7F_H_ */