From 215507d8d612d4269723b49aaf28468b634f68ac Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 9 Jun 2016 19:05:47 -0700 Subject: Avoid casts via correct types in fgas_textbreak FLW_DATEINFO cast not required. Review-Url: https://codereview.chromium.org/2053963002 --- xfa/fgas/layout/fgas_textbreak.cpp | 70 +++++++++++++++-------------- xfa/fgas/layout/fgas_textbreak.h | 12 ++--- xfa/fwl/basewidget/fwl_monthcalendarimp.cpp | 33 +++++++------- xfa/fxfa/app/xfa_rendercontext.cpp | 2 +- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index 8ba3ae818d..56850c741c 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -15,6 +15,24 @@ #include "xfa/fgas/layout/fgas_linebreak.h" #include "xfa/fgas/layout/fgas_unicode.h" +namespace { + +typedef uint32_t (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)( + CFX_TxtChar* pCurChar, + int32_t iRotation); +const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { + &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Tab, + &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Control, + &CFX_TxtBreak::AppendChar_Combination, &CFX_TxtBreak::AppendChar_Others, + &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Arabic, + &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, + &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, + &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Others, + &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Others, +}; + +} // namespace + CFX_TxtBreak::CFX_TxtBreak(uint32_t dwPolicies) : m_dwPolicies(dwPolicies), m_iLineWidth(2000000), @@ -212,7 +230,7 @@ void CFX_TxtBreak::SetBreakStatus() { if (iCount < 1) { return; } - CFX_TxtChar* pTC = (CFX_TxtChar*)m_pCurLine->GetCharPtr(iCount - 1); + CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); if (pTC->m_dwStatus == 0) { pTC->m_dwStatus = FX_TXTBREAK_PieceBreak; } @@ -311,10 +329,11 @@ void CFX_TxtBreak::ResetArabicContext() { m_bArabicComma = m_bArabicNumber; ResetContextCharStyles(); } -void CFX_TxtBreak::AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps) { +void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar, + uint32_t dwProps) { if (!m_bPagination) { - ((CFX_TxtChar*)pCurChar)->m_dwStatus = 0; - ((CFX_TxtChar*)pCurChar)->m_pUserData = m_pUserData; + pCurChar->m_dwStatus = 0; + pCurChar->m_pUserData = m_pUserData; } if (m_bArabicContext || m_bArabicShapes) { int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; @@ -330,7 +349,7 @@ void CFX_TxtBreak::AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps) { } ResetArabicContext(); if (!m_bPagination) { - CFX_TxtChar* pLastChar = (CFX_TxtChar*)GetLastChar(1, FALSE); + CFX_TxtChar* pLastChar = GetLastChar(1, FALSE); if (pLastChar != NULL && pLastChar->m_dwStatus < 1) { pLastChar->m_dwStatus = FX_TXTBREAK_PieceBreak; } @@ -339,13 +358,11 @@ void CFX_TxtBreak::AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps) { } pCurChar->m_dwCharStyles = m_dwContextCharStyles; } -uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar, +uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar, int32_t iRotation) { - ASSERT(pCurChar != NULL); FX_WCHAR wch = pCurChar->m_wCharCode; FX_WCHAR wForm; int32_t iCharWidth = 0; - CFX_Char* pLastChar; pCurChar->m_iCharWidth = -1; if (m_bCombText) { iCharWidth = m_iCombWidth; @@ -355,10 +372,9 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar, } else { wForm = wch; if (!m_bPagination) { - pLastChar = GetLastChar(0, FALSE); - if (pLastChar != NULL && - (((CFX_TxtChar*)pLastChar)->m_dwCharStyles & - FX_TXTCHARSTYLE_ArabicShadda) == 0) { + CFX_TxtChar* pLastChar = GetLastChar(0, FALSE); + if (pLastChar && + (pLastChar->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicShadda) == 0) { FX_BOOL bShadda = FALSE; if (wch == 0x0651) { FX_WCHAR wLast = pLastChar->m_wCharCode; @@ -373,11 +389,9 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar, } } if (bShadda) { - ((CFX_TxtChar*)pLastChar)->m_dwCharStyles |= - FX_TXTCHARSTYLE_ArabicShadda; - ((CFX_TxtChar*)pLastChar)->m_iCharWidth = 0; - ((CFX_TxtChar*)pCurChar)->m_dwCharStyles |= - FX_TXTCHARSTYLE_ArabicShadda; + pLastChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; + pLastChar->m_iCharWidth = 0; + pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; } } } @@ -391,7 +405,8 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar, pCurChar->m_iCharWidth = -iCharWidth; return FX_TXTBREAK_None; } -uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_Char* pCurChar, int32_t iRotation) { +uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, + int32_t iRotation) { m_eCharType = FX_CHARTYPE_Tab; if ((m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ExpandTab) == 0) { return FX_TXTBREAK_None; @@ -418,7 +433,7 @@ uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_Char* pCurChar, int32_t iRotation) { } return FX_TXTBREAK_None; } -uint32_t CFX_TxtBreak::AppendChar_Control(CFX_Char* pCurChar, +uint32_t CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar, int32_t iRotation) { m_eCharType = FX_CHARTYPE_Control; uint32_t dwRet = FX_TXTBREAK_None; @@ -447,7 +462,7 @@ uint32_t CFX_TxtBreak::AppendChar_Control(CFX_Char* pCurChar, } return dwRet; } -uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_Char* pCurChar, +uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar, int32_t iRotation) { FX_CHARTYPE chartype = pCurChar->GetCharType(); int32_t& iLineWidth = m_pCurLine->m_iWidth; @@ -510,7 +525,7 @@ uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_Char* pCurChar, } return FX_TXTBREAK_None; } -uint32_t CFX_TxtBreak::AppendChar_Others(CFX_Char* pCurChar, +uint32_t CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar, int32_t iRotation) { uint32_t dwProps = pCurChar->m_dwCharProps; FX_CHARTYPE chartype = pCurChar->GetCharType(); @@ -553,18 +568,7 @@ uint32_t CFX_TxtBreak::AppendChar_Others(CFX_Char* pCurChar, } return FX_TXTBREAK_None; } -typedef uint32_t (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)(CFX_Char* pCurChar, - int32_t iRotation); -static const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { - &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Tab, - &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Control, - &CFX_TxtBreak::AppendChar_Combination, &CFX_TxtBreak::AppendChar_Others, - &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Arabic, - &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, - &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Arabic, - &CFX_TxtBreak::AppendChar_Arabic, &CFX_TxtBreak::AppendChar_Others, - &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Others, -}; + uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) { uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch]; FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index 9943eab2c7..94fa79f5a6 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -262,12 +262,12 @@ class CFX_TxtBreak { int32_t GetCharRects(const FX_TXTRUN* pTxtRun, CFX_RectFArray& rtArray, FX_BOOL bCharBBox = FALSE) const; - void AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps); - uint32_t AppendChar_Combination(CFX_Char* pCurChar, int32_t iRotation); - uint32_t AppendChar_Tab(CFX_Char* pCurChar, int32_t iRotation); - uint32_t AppendChar_Control(CFX_Char* pCurChar, int32_t iRotation); - uint32_t AppendChar_Arabic(CFX_Char* pCurChar, int32_t iRotation); - uint32_t AppendChar_Others(CFX_Char* pCurChar, int32_t iRotation); + void AppendChar_PageLoad(CFX_TxtChar* pCurChar, uint32_t dwProps); + uint32_t AppendChar_Combination(CFX_TxtChar* pCurChar, int32_t iRotation); + uint32_t AppendChar_Tab(CFX_TxtChar* pCurChar, int32_t iRotation); + uint32_t AppendChar_Control(CFX_TxtChar* pCurChar, int32_t iRotation); + uint32_t AppendChar_Arabic(CFX_TxtChar* pCurChar, int32_t iRotation); + uint32_t AppendChar_Others(CFX_TxtChar* pCurChar, int32_t iRotation); private: void SetBreakStatus(); diff --git a/xfa/fwl/basewidget/fwl_monthcalendarimp.cpp b/xfa/fwl/basewidget/fwl_monthcalendarimp.cpp index e8672e67dc..ae5e71780b 100644 --- a/xfa/fwl/basewidget/fwl_monthcalendarimp.cpp +++ b/xfa/fwl/basewidget/fwl_monthcalendarimp.cpp @@ -391,7 +391,7 @@ void CFWL_MonthCalendarImp::DrawDatesInBK(CFX_Graphics* pGraphics, } int32_t iCount = m_arrDates.GetSize(); for (int32_t j = 0; j < iCount; j++) { - FWL_DATEINFO* pDataInfo = (FWL_DATEINFO*)m_arrDates.GetAt(j); + FWL_DATEINFO* pDataInfo = m_arrDates.GetAt(j); if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { params.m_dwStates |= CFWL_PartState_Selected; if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == @@ -521,7 +521,7 @@ void CFWL_MonthCalendarImp::DrawDatesIn(CFX_Graphics* pGraphics, } int32_t iCount = m_arrDates.GetSize(); for (int32_t j = 0; j < iCount; j++) { - FWL_DATEINFO* pDataInfo = (FWL_DATEINFO*)m_arrDates.GetAt(j); + FWL_DATEINFO* pDataInfo = m_arrDates.GetAt(j); params.m_wsText = pDataInfo->wsDay; params.m_rtPart = pDataInfo->rect; params.m_dwStates = pDataInfo->dwStates; @@ -558,7 +558,7 @@ void CFWL_MonthCalendarImp::DrawDatesInCircle(CFX_Graphics* pGraphics, if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) { return; } - FWL_DATEINFO* pDate = (FWL_DATEINFO*)m_arrDates[m_iDay - 1]; + FWL_DATEINFO* pDate = m_arrDates[m_iDay - 1]; if (!pDate) return; CFWL_ThemeBackground params; @@ -715,7 +715,7 @@ void CFWL_MonthCalendarImp::CalDateItem() { FX_FLOAT fTop = m_rtDates.top; int32_t iCount = m_arrDates.GetSize(); for (int32_t i = 0; i < iCount; i++) { - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(i); + FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(i); if (bNewWeek) { iWeekOfMonth++; bNewWeek = FALSE; @@ -851,14 +851,14 @@ FX_BOOL CFWL_MonthCalendarImp::InitDate() { m_dtMax = DATE(2200, 1, 1); return TRUE; } + void CFWL_MonthCalendarImp::ClearDateItem() { - int32_t iCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - FWL_DATEINFO* pData = (FWL_DATEINFO*)m_arrDates.GetAt(i); - delete pData; - } + for (int32_t i = 0; i < m_arrDates.GetSize(); i++) + delete m_arrDates.GetAt(i); + m_arrDates.RemoveAll(); } + void CFWL_MonthCalendarImp::ReSetDateItem() { m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); @@ -934,7 +934,7 @@ FX_BOOL CFWL_MonthCalendarImp::RemoveSelDay(int32_t iDay, FX_BOOL bAll) { for (int32_t i = 0; i < iCount; i++) { int32_t iSelDay = m_arrSelDays.GetAt(i); if (iSelDay <= iDatesCount) { - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iSelDay - 1); + FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; } } @@ -947,7 +947,7 @@ FX_BOOL CFWL_MonthCalendarImp::RemoveSelDay(int32_t iDay, FX_BOOL bAll) { int32_t iSelDay = m_arrSelDays.GetAt(iDay); int32_t iDatesCount = m_arrDates.GetSize(); if (iSelDay <= iDatesCount) { - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iSelDay - 1); + FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; } m_arrSelDays.RemoveAt(index); @@ -961,7 +961,7 @@ FX_BOOL CFWL_MonthCalendarImp::AddSelDay(int32_t iDay) { if (m_arrSelDays.Find(iDay) == -1) { RemoveSelDay(-1, TRUE); if (iDay <= m_arrDates.GetSize()) { - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iDay - 1); + FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; } m_arrSelDays.Add(iDay); @@ -1001,7 +1001,7 @@ void CFWL_MonthCalendarImp::GetTodayText(int32_t iYear, int32_t CFWL_MonthCalendarImp::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { int32_t iCount = m_arrDates.GetSize(); for (int32_t i = 0; i < iCount; i++) { - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(i); + FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(i); if (pDateInfo->rect.Contains(x, y)) { return ++i; } @@ -1012,7 +1012,7 @@ FX_BOOL CFWL_MonthCalendarImp::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { if (iDay <= 0 || iDay > m_arrDates.GetSize()) { return FALSE; } - FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates[iDay - 1]; + FWL_DATEINFO* pDateInfo = m_arrDates[iDay - 1]; if (!pDateInfo) return FALSE; rtDay = pDateInfo->rect; @@ -1114,11 +1114,10 @@ void CFWL_MonthCalendarImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); FX_BOOL bSelChanged = iCurSel > 0 && iCurSel != iOldSel; if (bSelChanged) { - FWL_DATEINFO* lpDatesInfo = - (FWL_DATEINFO*)m_pOwner->m_arrDates.GetAt(iCurSel - 1); + FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); CFX_RectF rtInvalidate(lpDatesInfo->rect); if (iOldSel > 0) { - lpDatesInfo = (FWL_DATEINFO*)m_pOwner->m_arrDates.GetAt(iOldSel - 1); + lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); rtInvalidate.Union(lpDatesInfo->rect); } m_pOwner->AddSelDay(iCurSel); diff --git a/xfa/fxfa/app/xfa_rendercontext.cpp b/xfa/fxfa/app/xfa_rendercontext.cpp index de78a202ad..bbb11cb5ec 100644 --- a/xfa/fxfa/app/xfa_rendercontext.cpp +++ b/xfa/fxfa/app/xfa_rendercontext.cpp @@ -51,7 +51,7 @@ int32_t CXFA_RenderContext::StartRender(CXFA_FFPageView* pPageView, int32_t CXFA_RenderContext::DoRender(IFX_Pause* pPause) { int32_t iCount = 0; while (m_pWidget) { - CXFA_FFWidget* pWidget = (CXFA_FFWidget*)m_pWidget; + CXFA_FFWidget* pWidget = m_pWidget; CFX_RectF rtWidgetBox; pWidget->GetBBox(rtWidgetBox, XFA_WidgetStatus_Visible); rtWidgetBox.width += 1; -- cgit v1.2.3