diff options
author | Lei Zhang <thestig@chromium.org> | 2017-08-01 14:00:19 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-01 21:31:41 +0000 |
commit | 04f736099c065d83193d2ceeccd6d125d7fe789d (patch) | |
tree | 0b4c5809f01db0556fcaa138d1d162c25d4684c9 | |
parent | 98073c826b6eb1b78f8dc695577d09d4ee9cf6b8 (diff) | |
download | pdfium-04f736099c065d83193d2ceeccd6d125d7fe789d.tar.xz |
Encapsulate some CFX_Char members.
Change-Id: Iab34de5858ae06582023be220ef7dd0d1d0a91c9
Reviewed-on: https://pdfium-review.googlesource.com/9530
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
-rw-r--r-- | core/fxcrt/cfx_char.cpp | 31 | ||||
-rw-r--r-- | core/fxcrt/cfx_char.h | 20 | ||||
-rw-r--r-- | core/fxcrt/fx_arabic.cpp | 13 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_breakline.cpp | 2 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_breakpiece.cpp | 2 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_rtfbreak.cpp | 34 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_txtbreak.cpp | 61 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_txtbreak.h | 1 |
8 files changed, 68 insertions, 96 deletions
diff --git a/core/fxcrt/cfx_char.cpp b/core/fxcrt/cfx_char.cpp index 1c166353f1..bc04b0fd72 100644 --- a/core/fxcrt/cfx_char.cpp +++ b/core/fxcrt/cfx_char.cpp @@ -6,36 +6,27 @@ #include "core/fxcrt/cfx_char.h" -CFX_Char::CFX_Char() +CFX_Char::CFX_Char(uint16_t wCharCode, uint32_t dwCharProps) + : CFX_Char(wCharCode, dwCharProps, 100, 100) {} + +CFX_Char::CFX_Char(uint16_t wCharCode, + uint32_t dwCharProps, + int32_t iHorizontalScale, + int32_t iVerticalScale) : m_dwStatus(CFX_BreakType::None), m_nBreakType(0), m_dwCharStyles(0), - m_dwCharProps(0), m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVerticalScale(100), m_iBidiClass(0), m_iBidiLevel(0), m_iBidiPos(0), m_iBidiOrder(0), - m_wCharCode(0), m_iFontSize(0), - m_dwIdentity(0) {} - -CFX_Char::CFX_Char(uint16_t wCharCode, uint32_t dwCharProps) - : m_nBreakType(0), - m_dwCharStyles(0), - m_dwCharProps(dwCharProps), - m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVerticalScale(100), - m_iBidiClass(0), - m_iBidiLevel(0), - m_iBidiPos(0), - m_iBidiOrder(0), + m_dwIdentity(0), m_wCharCode(wCharCode), - m_iFontSize(0), - m_dwIdentity(0) {} + m_dwCharProps(dwCharProps), + m_iHorizontalScale(iHorizontalScale), + m_iVerticalScale(iVerticalScale) {} CFX_Char::CFX_Char(const CFX_Char& other) = default; diff --git a/core/fxcrt/cfx_char.h b/core/fxcrt/cfx_char.h index cd0166feb2..009e87b388 100644 --- a/core/fxcrt/cfx_char.h +++ b/core/fxcrt/cfx_char.h @@ -15,28 +15,38 @@ enum class CFX_BreakType { None = 0, Piece, Line, Paragraph, Page }; class CFX_Char { public: - CFX_Char(); CFX_Char(uint16_t wCharCode, uint32_t dwCharProps); + CFX_Char(uint16_t wCharCode, + uint32_t dwCharProps, + int32_t iHorizontalScale, + int32_t iVerticalScale); CFX_Char(const CFX_Char& other); ~CFX_Char(); FX_CHARTYPE GetCharType() const; + uint16_t char_code() const { return m_wCharCode; } + uint32_t char_props() const { return m_dwCharProps; } + int16_t horizonal_scale() const { return m_iHorizontalScale; } + int16_t vertical_scale() const { return m_iVerticalScale; } + CFX_BreakType m_dwStatus; uint8_t m_nBreakType; uint32_t m_dwCharStyles; - uint32_t m_dwCharProps; int32_t m_iCharWidth; - int32_t m_iHorizontalScale; - int32_t m_iVerticalScale; int16_t m_iBidiClass; int16_t m_iBidiLevel; int16_t m_iBidiPos; int16_t m_iBidiOrder; - uint16_t m_wCharCode; int32_t m_iFontSize; uint32_t m_dwIdentity; CFX_RetainPtr<CFX_Retainable> m_pUserData; + + private: + uint16_t m_wCharCode; + uint32_t m_dwCharProps; + int32_t m_iHorizontalScale; + int32_t m_iVerticalScale; }; #endif // CORE_FXCRT_CFX_CHAR_H_ diff --git a/core/fxcrt/fx_arabic.cpp b/core/fxcrt/fx_arabic.cpp index 095db8d728..fecfc3f759 100644 --- a/core/fxcrt/fx_arabic.cpp +++ b/core/fxcrt/fx_arabic.cpp @@ -336,7 +336,7 @@ const FX_ARBFORMTABLE* ParseChar(const CFX_Char* pTC, } *eType = pTC->GetCharType(); - *wChar = static_cast<wchar_t>(pTC->m_wCharCode); + *wChar = static_cast<wchar_t>(pTC->char_code()); const FX_ARBFORMTABLE* pFT = GetArabicFormTable(*wChar); if (!pFT || *eType >= FX_CHARTYPE_ArabicNormal) *eType = FX_CHARTYPE_Unknown; @@ -424,17 +424,18 @@ class CFX_BidiLine { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(*chars)); if (bWS) { for (int32_t i = 0; i < iCount; i++) { - (*chars)[i].m_iBidiClass = - static_cast<int16_t>((*chars)[i].m_dwCharProps & - FX_BIDICLASSBITSMASK) >> + CFX_Char& cur = (*chars)[i]; + cur.m_iBidiClass = + static_cast<int16_t>(cur.char_props() & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; } return; } for (int32_t i = 0; i < iCount; i++) { - (*chars)[i].m_iBidiClass = static_cast<int16_t>( - gc_FX_BidiNTypes[((*chars)[i].m_dwCharProps & FX_BIDICLASSBITSMASK) >> + CFX_Char& cur = (*chars)[i]; + cur.m_iBidiClass = static_cast<int16_t>( + gc_FX_BidiNTypes[(cur.char_props() & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS]); } } diff --git a/xfa/fgas/layout/cfx_breakline.cpp b/xfa/fgas/layout/cfx_breakline.cpp index 562f984ffe..9eb0211119 100644 --- a/xfa/fgas/layout/cfx_breakline.cpp +++ b/xfa/fgas/layout/cfx_breakline.cpp @@ -39,7 +39,7 @@ void CFX_BreakLine::GetString(CFX_WideString& wsStr) const { int32_t iCount = pdfium::CollectionSize<int32_t>(m_LineChars); wchar_t* pBuf = wsStr.GetBuffer(iCount); for (int32_t i = 0; i < iCount; i++) - *pBuf++ = static_cast<wchar_t>(m_LineChars[i].m_wCharCode); + *pBuf++ = static_cast<wchar_t>(m_LineChars[i].char_code()); wsStr.ReleaseBuffer(iCount); } diff --git a/xfa/fgas/layout/cfx_breakpiece.cpp b/xfa/fgas/layout/cfx_breakpiece.cpp index 605b900a6e..70ac66e8ba 100644 --- a/xfa/fgas/layout/cfx_breakpiece.cpp +++ b/xfa/fgas/layout/cfx_breakpiece.cpp @@ -38,7 +38,7 @@ CFX_WideString CFX_BreakPiece::GetString() const { CFX_WideString ret; ret.Reserve(m_iChars); for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++) - ret += static_cast<wchar_t>((*m_pChars)[i].m_wCharCode); + ret += static_cast<wchar_t>((*m_pChars)[i].char_code()); return ret; } diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp index 353bdbacdf..45acae5bc4 100644 --- a/xfa/fgas/layout/cfx_rtfbreak.cpp +++ b/xfa/fgas/layout/cfx_rtfbreak.cpp @@ -68,16 +68,10 @@ CFX_BreakType CFX_RTFBreak::AppendChar(wchar_t wch) { uint32_t dwProps = FX_GetUnicodeProperties(wch); FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); - m_pCurLine->m_LineChars.emplace_back(); - + m_pCurLine->m_LineChars.emplace_back(wch, dwProps, m_iHorizontalScale, + m_iVerticalScale); CFX_Char* pCurChar = &m_pCurLine->m_LineChars.back(); - pCurChar->m_dwStatus = CFX_BreakType::None; - pCurChar->m_wCharCode = wch; - pCurChar->m_dwCharProps = dwProps; pCurChar->m_iFontSize = m_iFontSize; - pCurChar->m_iHorizontalScale = m_iHorizontalScale; - pCurChar->m_iVerticalScale = m_iVerticalScale; - pCurChar->m_iCharWidth = 0; pCurChar->m_dwIdentity = m_dwIdentity; pCurChar->m_pUserData = m_pUserData; @@ -127,7 +121,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar(wchar_t wch) { void CFX_RTFBreak::AppendChar_Combination(CFX_Char* pCurChar) { int32_t iCharWidth = 0; - if (!m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth, false)) + if (!m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth, false)) iCharWidth = 0; iCharWidth *= m_iFontSize; @@ -160,7 +154,7 @@ void CFX_RTFBreak::AppendChar_Tab(CFX_Char* pCurChar) { CFX_BreakType CFX_RTFBreak::AppendChar_Control(CFX_Char* pCurChar) { CFX_BreakType dwRet2 = CFX_BreakType::None; - switch (pCurChar->m_wCharCode) { + switch (pCurChar->char_code()) { case L'\v': case 0x2028: dwRet2 = CFX_BreakType::Line; @@ -172,7 +166,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Control(CFX_Char* pCurChar) { dwRet2 = CFX_BreakType::Paragraph; break; default: - if (pCurChar->m_wCharCode == m_wParagraphBreakChar) + if (pCurChar->char_code() == m_wParagraphBreakChar) dwRet2 = CFX_BreakType::Paragraph; break; } @@ -197,7 +191,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { bAlef = (wForm == 0xFEFF && pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) && - !m_pFont->GetCharWidth(pLastChar->m_wCharCode, iCharWidth, false)) { + !m_pFont->GetCharWidth(pLastChar->char_code(), iCharWidth, false)) { iCharWidth = m_iDefChar; } @@ -212,7 +206,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar, nullptr); if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) && - !m_pFont->GetCharWidth(pCurChar->m_wCharCode, iCharWidth, false)) { + !m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth, false)) { iCharWidth = m_iDefChar; } @@ -229,7 +223,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { CFX_BreakType CFX_RTFBreak::AppendChar_Others(CFX_Char* pCurChar) { FX_CHARTYPE chartype = pCurChar->GetCharType(); - wchar_t wForm = pCurChar->m_wCharCode; + wchar_t wForm = pCurChar->char_code(); int32_t iCharWidth = 0; if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) iCharWidth = m_iDefChar; @@ -335,8 +329,8 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_BreakLine* pNextLine, tp.m_iWidth = 0; tp.m_dwStatus = pTC->m_dwStatus; tp.m_iFontSize = pTC->m_iFontSize; - tp.m_iHorizontalScale = pTC->m_iHorizontalScale; - tp.m_iVerticalScale = pTC->m_iVerticalScale; + tp.m_iHorizontalScale = pTC->horizonal_scale(); + tp.m_iVerticalScale = pTC->vertical_scale(); dwIdentity = pTC->m_dwIdentity; tp.m_dwIdentity = dwIdentity; tp.m_pUserData = pTC->m_pUserData.As<CXFA_TextUserData>(); @@ -408,8 +402,8 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, tp.m_iBidiLevel = iBidiLevel; tp.m_iBidiPos = pTC->m_iBidiOrder; tp.m_iFontSize = pTC->m_iFontSize; - tp.m_iHorizontalScale = pTC->m_iHorizontalScale; - tp.m_iVerticalScale = pTC->m_iVerticalScale; + tp.m_iHorizontalScale = pTC->horizonal_scale(); + tp.m_iVerticalScale = pTC->vertical_scale(); dwIdentity = pTC->m_dwIdentity; tp.m_dwIdentity = dwIdentity; tp.m_pUserData = pTC->m_pUserData.As<CXFA_TextUserData>(); @@ -558,7 +552,7 @@ int32_t CFX_RTFBreak::GetBreakPos(std::vector<CFX_Char>& tca, if (bAllChars) pCur->m_nBreakType = FX_LBT_UNKNOWN; - uint32_t nCodeProp = pCur->m_dwCharProps; + uint32_t nCodeProp = pCur->char_props(); uint32_t nNext = nCodeProp & 0x003F; int32_t iCharWidth = pCur->m_iCharWidth; if (iCharWidth > 0) @@ -566,7 +560,7 @@ int32_t CFX_RTFBreak::GetBreakPos(std::vector<CFX_Char>& tca, while (iLength >= 0) { pCur = pCharArray + iLength; - nCodeProp = pCur->m_dwCharProps; + nCodeProp = pCur->char_props(); uint32_t nCur = nCodeProp & 0x003F; bool bNeedBreak = false; FX_LINEBREAKTYPE eType; diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp index a5a5822d1c..9e4e445e0a 100644 --- a/xfa/fgas/layout/cfx_txtbreak.cpp +++ b/xfa/fgas/layout/cfx_txtbreak.cpp @@ -45,13 +45,8 @@ void CFX_TxtBreak::SetCombWidth(float fCombWidth) { m_iCombWidth = FXSYS_round(fCombWidth * 20000.0f); } -void CFX_TxtBreak::AppendChar_PageLoad(CFX_Char* pCurChar) { - pCurChar->m_dwStatus = CFX_BreakType::None; - pCurChar->m_dwCharStyles = m_iAlignment | (1 << 8); -} - void CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar) { - wchar_t wch = pCurChar->m_wCharCode; + wchar_t wch = pCurChar->char_code(); wchar_t wForm; int32_t iCharWidth = 0; pCurChar->m_iCharWidth = -1; @@ -64,13 +59,13 @@ void CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar) { (pLastChar->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicShadda) == 0) { bool bShadda = false; if (wch == 0x0651) { - wchar_t wLast = pLastChar->m_wCharCode; + wchar_t wLast = pLastChar->char_code(); if (wLast >= 0x064C && wLast <= 0x0650) { wForm = FX_GetArabicFromShaddaTable(wLast); bShadda = true; } } else if (wch >= 0x064C && wch <= 0x0650) { - if (pLastChar->m_wCharCode == 0x0651) { + if (pLastChar->char_code() == 0x0651) { wForm = FX_GetArabicFromShaddaTable(wch); bShadda = true; } @@ -98,7 +93,7 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Control(CFX_Char* pCurChar) { m_eCharType = FX_CHARTYPE_Control; CFX_BreakType dwRet = CFX_BreakType::None; if (!m_bSingleLine) { - wchar_t wch = pCurChar->m_wCharCode; + wchar_t wch = pCurChar->char_code(); switch (wch) { case L'\v': case 0x2028: @@ -180,7 +175,7 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Others(CFX_Char* pCurChar) { int32_t& iLineWidth = m_pCurLine->m_iWidth; int32_t iCharWidth = 0; m_eCharType = chartype; - wchar_t wch = pCurChar->m_wCharCode; + wchar_t wch = pCurChar->char_code(); wchar_t wForm = wch; if (m_bCombText) { @@ -207,22 +202,11 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Others(CFX_Char* pCurChar) { CFX_BreakType CFX_TxtBreak::AppendChar(wchar_t wch) { uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)]; FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); - m_pCurLine->m_LineChars.emplace_back(); - + m_pCurLine->m_LineChars.emplace_back(wch, dwProps, m_iHorizontalScale, + m_iVerticalScale); CFX_Char* pCurChar = &m_pCurLine->m_LineChars.back(); - pCurChar->m_wCharCode = static_cast<uint16_t>(wch); - pCurChar->m_dwCharProps = dwProps; - pCurChar->m_dwCharStyles = 0; - pCurChar->m_iCharWidth = 0; - pCurChar->m_iHorizontalScale = m_iHorizontalScale; - pCurChar->m_iVerticalScale = m_iVerticalScale; - pCurChar->m_dwStatus = CFX_BreakType::None; - pCurChar->m_iBidiClass = 0; - pCurChar->m_iBidiLevel = 0; - pCurChar->m_iBidiPos = 0; - pCurChar->m_iBidiOrder = 0; - - AppendChar_PageLoad(pCurChar); + pCurChar->m_dwCharStyles = m_iAlignment | (1 << 8); + CFX_BreakType dwRet1 = CFX_BreakType::None; if (chartype != FX_CHARTYPE_Combination && GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype) && @@ -333,8 +317,8 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, tp.m_iBidiLevel = iBidiLevel; tp.m_iBidiPos = pTC->m_iBidiOrder; tp.m_dwCharStyles = pTC->m_dwCharStyles; - tp.m_iHorizontalScale = pTC->m_iHorizontalScale; - tp.m_iVerticalScale = pTC->m_iVerticalScale; + tp.m_iHorizontalScale = pTC->horizonal_scale(); + tp.m_iVerticalScale = pTC->vertical_scale(); tp.m_dwStatus = CFX_BreakType::Piece; } if (iBidiLevel != pTC->m_iBidiLevel || @@ -393,8 +377,8 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, tp.m_pChars = &m_pCurLine->m_LineChars; pTC = &chars[0]; tp.m_dwCharStyles = pTC->m_dwCharStyles; - tp.m_iHorizontalScale = pTC->m_iHorizontalScale; - tp.m_iVerticalScale = pTC->m_iVerticalScale; + tp.m_iHorizontalScale = pTC->horizonal_scale(); + tp.m_iVerticalScale = pTC->vertical_scale(); m_pCurLine->m_LinePieces.push_back(tp); tpos->push_back({0, 0}); } @@ -546,7 +530,7 @@ int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_Char>& ca, if (bAllChars) pCur->m_nBreakType = FX_LBT_UNKNOWN; - nCodeProp = pCur->m_dwCharProps; + nCodeProp = pCur->char_props(); nNext = nCodeProp & 0x003F; int32_t iCharWidth = pCur->m_iCharWidth; if (iCharWidth > 0) @@ -554,19 +538,12 @@ int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_Char>& ca, while (iLength >= 0) { pCur = &ca[iLength]; - nCodeProp = pCur->m_dwCharProps; + nCodeProp = pCur->char_props(); nCur = nCodeProp & 0x003F; - if (nCur == FX_CBP_SP) { - if (nNext == FX_CBP_SP) - eType = FX_LBT_PROHIBITED_BRK; - else - eType = gs_FX_LineBreak_PairTable[nCur][nNext]; - } else { - if (nNext == FX_CBP_SP) - eType = FX_LBT_PROHIBITED_BRK; - else - eType = gs_FX_LineBreak_PairTable[nCur][nNext]; - } + if (nNext == FX_CBP_SP) + eType = FX_LBT_PROHIBITED_BRK; + else + eType = gs_FX_LineBreak_PairTable[nCur][nNext]; if (bAllChars) pCur->m_nBreakType = static_cast<uint8_t>(eType); if (!bOnlyBrk) { diff --git a/xfa/fgas/layout/cfx_txtbreak.h b/xfa/fgas/layout/cfx_txtbreak.h index 3cb483c84e..0529c2656c 100644 --- a/xfa/fgas/layout/cfx_txtbreak.h +++ b/xfa/fgas/layout/cfx_txtbreak.h @@ -76,7 +76,6 @@ class CFX_TxtBreak : public CFX_Break { private: void AppendChar_Combination(CFX_Char* pCurChar); void AppendChar_Tab(CFX_Char* pCurChar); - void AppendChar_PageLoad(CFX_Char* pCurChar); CFX_BreakType AppendChar_Control(CFX_Char* pCurChar); CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar); CFX_BreakType AppendChar_Others(CFX_Char* pCurChar); |