Skip to content

Commit

Permalink
Merge pull request #1415 from beru/reuse_vDxArray
Browse files Browse the repository at this point in the history
テキスト幅計算に使用する文字間隔配列のコンテナを使いまわす事で負荷を削減
  • Loading branch information
beru authored Sep 27, 2020
2 parents 470a1ff + c4a7fa6 commit b1fc7a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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 //!< 文字列長
) 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] 文字間隔配列
);

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_ */

0 comments on commit b1fc7a5

Please sign in to comment.