From d7de8e15eaae5a37abfcb8d1cf7028fbcebbaccd Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 28 Feb 2017 10:37:00 -0500 Subject: Convert FX_RTFLINEALIGNMENT to an enum class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl removes unused items and converts the remaining members to an enum class. Change-Id: I86e95231275ab20f274a5913715c1579a6fbc5dc Reviewed-on: https://pdfium-review.googlesource.com/2875 Reviewed-by: Tom Sepez Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- xfa/fgas/layout/fgas_rtfbreak.cpp | 24 +++++++++--------------- xfa/fgas/layout/fgas_rtfbreak.h | 38 +++++++++----------------------------- xfa/fxfa/app/cxfa_textlayout.cpp | 23 ++++++++++++----------- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index ddb9164ea7..ce6de0de66 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -34,7 +34,7 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles) m_bWordSpace(false), m_iWordSpace(0), m_bRTL(false), - m_iAlignment(FX_RTFLINEALIGNMENT_Left), + m_iAlignment(CFX_RTFLineAlignment::Left), m_pUserData(nullptr), m_eCharType(FX_CHARTYPE_Unknown), m_dwIdentity(0), @@ -196,11 +196,6 @@ void CFX_RTFBreak::SetWordSpace(bool bDefault, FX_FLOAT fWordSpace) { void CFX_RTFBreak::SetReadingOrder(bool bRTL) { m_bRTL = bRTL; } -void CFX_RTFBreak::SetAlignment(int32_t iAlignment) { - ASSERT(iAlignment >= FX_RTFLINEALIGNMENT_Left && - iAlignment <= FX_RTFLINEALIGNMENT_Distributed); - m_iAlignment = iAlignment; -} void CFX_RTFBreak::SetUserData(const CFX_RetainPtr& pUserData) { if (m_pUserData == pUserData) @@ -502,12 +497,13 @@ uint32_t CFX_RTFBreak::EndBreak(uint32_t dwStatus) { m_iReady = (m_pCurLine == &m_RTFLine1) ? 1 : 2; CFX_RTFLine* pNextLine = (m_pCurLine == &m_RTFLine1) ? &m_RTFLine2 : &m_RTFLine1; - bool bAllChars = (m_iAlignment > FX_RTFLINEALIGNMENT_Right); + bool bAllChars = m_iAlignment == CFX_RTFLineAlignment::Justified || + m_iAlignment == CFX_RTFLineAlignment::Distributed; CFX_TPOArray tpos(100); if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { EndBreak_BidiLine(tpos, dwStatus); - if (!m_bPagination && m_iAlignment > FX_RTFLINEALIGNMENT_Left) + if (!m_bPagination && m_iAlignment != CFX_RTFLineAlignment::Left) EndBreak_Alignment(tpos, bAllChars, dwStatus); } @@ -727,10 +723,8 @@ void CFX_RTFBreak::EndBreak_Alignment(CFX_TPOArray& tpos, } } int32_t iOffset = m_iBoundaryEnd - iNetWidth; - int32_t iLowerAlignment = (m_iAlignment & FX_RTFLINEALIGNMENT_LowerMask); - int32_t iHigherAlignment = (m_iAlignment & FX_RTFLINEALIGNMENT_HigherMask); - if (iGapChars > 0 && (iHigherAlignment == FX_RTFLINEALIGNMENT_Distributed || - (iHigherAlignment == FX_RTFLINEALIGNMENT_Justified && + if (iGapChars > 0 && (m_iAlignment == CFX_RTFLineAlignment::Distributed || + (m_iAlignment == CFX_RTFLineAlignment::Justified && dwStatus != FX_RTFBREAK_ParagraphBreak))) { int32_t iStart = -1; for (i = 0; i < iCount; i++) { @@ -758,10 +752,10 @@ void CFX_RTFBreak::EndBreak_Alignment(CFX_TPOArray& tpos, } iStart += ttp.m_iWidth; } - } else if (iLowerAlignment > FX_RTFLINEALIGNMENT_Left) { - if (iLowerAlignment == FX_RTFLINEALIGNMENT_Center) { + } else if (m_iAlignment == CFX_RTFLineAlignment::Right || + m_iAlignment == CFX_RTFLineAlignment::Center) { + if (m_iAlignment == CFX_RTFLineAlignment::Center) iOffset /= 2; - } if (iOffset > 0) { for (i = 0; i < iCount; i++) { CFX_RTFPiece& ttp = pCurPieces->GetAt(i); diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index cbc36ad09f..9119f9df3d 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -27,33 +27,13 @@ class CFGAS_GEFont; #define FX_RTFLAYOUTSTYLE_Pagination 0x01 #define FX_RTFLAYOUTSTYLE_ExpandTab 0x10 -#define FX_RTFCHARSTYLE_Alignment 0x000F -#define FX_RTFCHARSTYLE_ArabicNumber 0x0010 -#define FX_RTFCHARSTYLE_ArabicShadda 0x0020 -#define FX_RTFCHARSTYLE_OddBidiLevel 0x0040 -#define FX_RTFCHARSTYLE_RTLReadingOrder 0x0080 -#define FX_RTFCHARSTYLE_ArabicContext 0x0300 -#define FX_RTFCHARSTYLE_ArabicIndic 0x0400 -#define FX_RTFCHARSTYLE_ArabicComma 0x0800 -#define FX_RTFLINEALIGNMENT_Left 0 -#define FX_RTFLINEALIGNMENT_Center 1 -#define FX_RTFLINEALIGNMENT_Right 2 -#define FX_RTFLINEALIGNMENT_Justified (1 << 2) -#define FX_RTFLINEALIGNMENT_Distributed (2 << 2) -#define FX_RTFLINEALIGNMENT_JustifiedLeft \ - (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Justified) -#define FX_RTFLINEALIGNMENT_JustifiedCenter \ - (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Justified) -#define FX_RTFLINEALIGNMENT_JustifiedRight \ - (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Justified) -#define FX_RTFLINEALIGNMENT_DistributedLeft \ - (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Distributed) -#define FX_RTFLINEALIGNMENT_DistributedCenter \ - (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Distributed) -#define FX_RTFLINEALIGNMENT_DistributedRight \ - (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Distributed) -#define FX_RTFLINEALIGNMENT_LowerMask 0x03 -#define FX_RTFLINEALIGNMENT_HigherMask 0x0C +enum class CFX_RTFLineAlignment { + Left = 0, + Center, + Right, + Justified, + Distributed +}; struct FX_RTFTEXTOBJ { FX_RTFTEXTOBJ(); @@ -219,7 +199,7 @@ class CFX_RTFBreak { void SetCharSpace(FX_FLOAT fCharSpace); void SetWordSpace(bool bDefault, FX_FLOAT fWordSpace); void SetReadingOrder(bool bRTL = false); - void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left); + void SetAlignment(CFX_RTFLineAlignment align) { m_iAlignment = align; } void SetUserData(const CFX_RetainPtr& pUserData); uint32_t AppendChar(FX_WCHAR wch); uint32_t EndBreak(uint32_t dwStatus = FX_RTFBREAK_PieceBreak); @@ -281,7 +261,7 @@ class CFX_RTFBreak { bool m_bWordSpace; int32_t m_iWordSpace; bool m_bRTL; - int32_t m_iAlignment; + CFX_RTFLineAlignment m_iAlignment; CFX_RetainPtr m_pUserData; FX_CHARTYPE m_eCharType; uint32_t m_dwIdentity; diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp index a0e7fada82..fe0e249c1f 100644 --- a/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/xfa/fxfa/app/cxfa_textlayout.cpp @@ -108,26 +108,26 @@ void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { FX_FLOAT fStart = 0; FX_FLOAT fStartPos = 0; if (para) { - int32_t iAlign = FX_RTFLINEALIGNMENT_Left; + CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; switch (para.GetHorizontalAlign()) { case XFA_ATTRIBUTEENUM_Center: - iAlign = FX_RTFLINEALIGNMENT_Center; + iAlign = CFX_RTFLineAlignment::Center; break; case XFA_ATTRIBUTEENUM_Right: - iAlign = FX_RTFLINEALIGNMENT_Right; + iAlign = CFX_RTFLineAlignment::Right; break; case XFA_ATTRIBUTEENUM_Justify: - iAlign = FX_RTFLINEALIGNMENT_Justified; + iAlign = CFX_RTFLineAlignment::Justified; break; case XFA_ATTRIBUTEENUM_JustifyAll: - iAlign = FX_RTFLINEALIGNMENT_Distributed; + iAlign = CFX_RTFLineAlignment::Distributed; break; } m_pBreak->SetAlignment(iAlign); fStart = para.GetMarginLeft(); if (m_pTextProvider->IsCheckButtonAndAutoWidth()) { - if (iAlign != FX_RTFLINEALIGNMENT_Left) + if (iAlign != CFX_RTFLineAlignment::Left) fLineWidth -= para.GetMarginRight(); } else { fLineWidth -= para.GetMarginRight(); @@ -167,24 +167,25 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, if (eDisplay == FDE_CSSDisplay::Block || eDisplay == FDE_CSSDisplay::ListItem) { - int32_t iAlign = FX_RTFLINEALIGNMENT_Left; + CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; switch (pStyle->GetTextAlign()) { case FDE_CSSTextAlign::Right: - iAlign = FX_RTFLINEALIGNMENT_Right; + iAlign = CFX_RTFLineAlignment::Right; break; case FDE_CSSTextAlign::Center: - iAlign = FX_RTFLINEALIGNMENT_Center; + iAlign = CFX_RTFLineAlignment::Center; break; case FDE_CSSTextAlign::Justify: - iAlign = FX_RTFLINEALIGNMENT_Justified; + iAlign = CFX_RTFLineAlignment::Justified; break; case FDE_CSSTextAlign::JustifyAll: - iAlign = FX_RTFLINEALIGNMENT_Distributed; + iAlign = CFX_RTFLineAlignment::Distributed; break; default: break; } m_pBreak->SetAlignment(iAlign); + FX_FLOAT fStart = 0; const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); const FDE_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); -- cgit v1.2.3