Make FX_LAYOUTSTYLE a nested enum class [pdfium : main]

0 views
Skip to first unread message

Tom Sepez (Gerrit)

unread,
Aug 26, 2021, 6:57:37 PM8/26/21
to Lei Zhang, Pdfium LUCI CQ, pdfium-...@googlegroups.com

Attention is currently required from: Lei Zhang.

View Change

    To view, visit change 84470. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: pdfium
    Gerrit-Branch: main
    Gerrit-Change-Id: I7f2c903cfec8fc36bb1f6ae925d3bb4378b5c140
    Gerrit-Change-Number: 84470
    Gerrit-PatchSet: 1
    Gerrit-Owner: Tom Sepez <tse...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
    Gerrit-Attention: Lei Zhang <the...@chromium.org>
    Gerrit-Comment-Date: Thu, 26 Aug 2021 22:57:34 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Lei Zhang (Gerrit)

    unread,
    Aug 26, 2021, 7:21:09 PM8/26/21
    to Tom Sepez, Lei Zhang, Pdfium LUCI CQ, pdfium-...@googlegroups.com

    Attention is currently required from: Tom Sepez.

    Patch set 1:Code-Review +1

    View Change

      To view, visit change 84470. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: pdfium
      Gerrit-Branch: main
      Gerrit-Change-Id: I7f2c903cfec8fc36bb1f6ae925d3bb4378b5c140
      Gerrit-Change-Number: 84470
      Gerrit-PatchSet: 1
      Gerrit-Owner: Tom Sepez <tse...@chromium.org>
      Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
      Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
      Gerrit-Attention: Tom Sepez <tse...@chromium.org>
      Gerrit-Comment-Date: Thu, 26 Aug 2021 23:21:06 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Tom Sepez (Gerrit)

      unread,
      Aug 26, 2021, 8:29:34 PM8/26/21
      to Lei Zhang, Pdfium LUCI CQ, pdfium-...@googlegroups.com

      Attention is currently required from: Tom Sepez.

      Patch set 1:Commit-Queue +2

      View Change

        To view, visit change 84470. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I7f2c903cfec8fc36bb1f6ae925d3bb4378b5c140
        Gerrit-Change-Number: 84470
        Gerrit-PatchSet: 1
        Gerrit-Owner: Tom Sepez <tse...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
        Gerrit-Attention: Tom Sepez <tse...@chromium.org>
        Gerrit-Comment-Date: Fri, 27 Aug 2021 00:29:32 +0000

        Pdfium LUCI CQ (Gerrit)

        unread,
        Aug 26, 2021, 8:31:39 PM8/26/21
        to Tom Sepez, Lei Zhang, pdfium-...@googlegroups.com

        Pdfium LUCI CQ submitted this change.

        View Change


        Approvals: Lei Zhang: Looks good to me Tom Sepez: Commit
        Make FX_LAYOUTSTYLE a nested enum class

        -- Use Mask<>.
        -- reset the values (old values were an artifact from deleting unused
        flags some time ago).
        -- move one unrelated class to anon namespace because it was encountered
        while reading this code.
        -- pack tighter.

        Change-Id: I7f2c903cfec8fc36bb1f6ae925d3bb4378b5c140
        Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84470
        Reviewed-by: Lei Zhang <the...@chromium.org>
        Commit-Queue: Tom Sepez <tse...@chromium.org>
        ---
        M testing/fuzzers/pdf_bidi_fuzzer.cc
        M xfa/fde/cfde_texteditengine.cpp
        M xfa/fde/cfde_textout.cpp
        M xfa/fde/cfde_textout.h
        M xfa/fgas/layout/cfgas_break.cpp
        M xfa/fgas/layout/cfgas_break.h
        M xfa/fgas/layout/cfgas_rtfbreak.cpp
        M xfa/fgas/layout/cfgas_rtfbreak.h
        M xfa/fgas/layout/cfgas_rtfbreak_unittest.cpp
        M xfa/fgas/layout/cfgas_txtbreak.cpp
        M xfa/fgas/layout/cfgas_txtbreak.h
        M xfa/fxfa/cxfa_textlayout.cpp
        12 files changed, 51 insertions(+), 50 deletions(-)

        diff --git a/testing/fuzzers/pdf_bidi_fuzzer.cc b/testing/fuzzers/pdf_bidi_fuzzer.cc
        index 3c77b76..9b10eae 100644
        --- a/testing/fuzzers/pdf_bidi_fuzzer.cc
        +++ b/testing/fuzzers/pdf_bidi_fuzzer.cc
        @@ -22,7 +22,7 @@
        0);
        assert(font);

        - CFGAS_RTFBreak rtf_break(FX_LAYOUTSTYLE_ExpandTab);
        + CFGAS_RTFBreak rtf_break(CFGAS_Break::LayoutStyle::kExpandTab);
        rtf_break.SetLineBreakTolerance(1);
        rtf_break.SetFont(CFGAS_GEFont::LoadFont(std::move(font)));
        rtf_break.SetFontSize(12);
        diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
        index aae12e4..ce950a3 100644
        --- a/xfa/fde/cfde_texteditengine.cpp
        +++ b/xfa/fde/cfde_texteditengine.cpp
        @@ -667,11 +667,11 @@
        return;

        is_multiline_ = val;
        - uint32_t style = text_break_.GetLayoutStyles();
        + Mask<CFGAS_Break::LayoutStyle> style = text_break_.GetLayoutStyles();
        if (is_multiline_)
        - style &= ~FX_LAYOUTSTYLE_SingleLine;
        + style.Clear(CFGAS_Break::LayoutStyle::kSingleLine);
        else
        - style |= FX_LAYOUTSTYLE_SingleLine;
        + style |= CFGAS_Break::LayoutStyle::kSingleLine;

        text_break_.SetLayoutStyles(style);
        is_dirty_ = true;
        @@ -693,12 +693,12 @@

        is_comb_text_ = enable;

        - uint32_t style = text_break_.GetLayoutStyles();
        + Mask<CFGAS_Break::LayoutStyle> style = text_break_.GetLayoutStyles();
        if (enable) {
        - style |= FX_LAYOUTSTYLE_CombText;
        + style |= CFGAS_Break::LayoutStyle::kCombText;
        SetCombTextWidth();
        } else {
        - style &= ~FX_LAYOUTSTYLE_CombText;
        + style.Clear(CFGAS_Break::LayoutStyle::kCombText);
        }
        text_break_.SetLayoutStyles(style);
        is_dirty_ = true;
        diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
        index 0d77522..8fdbc03 100644
        --- a/xfa/fde/cfde_textout.cpp
        +++ b/xfa/fde/cfde_textout.cpp
        @@ -149,10 +149,9 @@

        void CFDE_TextOut::SetStyles(const FDE_TextStyle& dwStyles) {
        m_Styles = dwStyles;
        -
        - m_dwTxtBkStyles = 0;
        - if (m_Styles.single_line_)
        - m_dwTxtBkStyles |= FX_LAYOUTSTYLE_SingleLine;
        + m_dwTxtBkStyles = m_Styles.single_line_
        + ? CFGAS_Break::LayoutStyle::kSingleLine
        + : CFGAS_Break::LayoutStyle::kNone;

        m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles);
        }
        diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
        index 3d443da..db9be7f 100644
        --- a/xfa/fde/cfde_textout.h
        +++ b/xfa/fde/cfde_textout.h
        @@ -16,6 +16,7 @@
        #include "core/fxge/dib/fx_dib.h"
        #include "third_party/base/span.h"
        #include "xfa/fde/cfde_data.h"
        +#include "xfa/fgas/layout/cfgas_break.h"
        #include "xfa/fgas/layout/cfgas_char.h"

        class CFGAS_GEFont;
        @@ -110,7 +111,7 @@
        FDE_TextStyle m_Styles;
        std::vector<int32_t> m_CharWidths;
        FX_ARGB m_TxtColor = 0xFF000000;
        - uint32_t m_dwTxtBkStyles = 0;
        + Mask<CFGAS_Break::LayoutStyle> m_dwTxtBkStyles;
        WideString m_wsText;
        CFX_Matrix m_Matrix;
        std::deque<Line> m_ttoLines;
        diff --git a/xfa/fgas/layout/cfgas_break.cpp b/xfa/fgas/layout/cfgas_break.cpp
        index 363a7c5..e89a44e 100644
        --- a/xfa/fgas/layout/cfgas_break.cpp
        +++ b/xfa/fgas/layout/cfgas_break.cpp
        @@ -16,7 +16,7 @@
        const float CFGAS_Break::kConversionFactor = 20000.0f;
        const int CFGAS_Break::kMinimumTabWidth = 160000;

        -CFGAS_Break::CFGAS_Break(uint32_t dwLayoutStyles)
        +CFGAS_Break::CFGAS_Break(Mask<LayoutStyle> dwLayoutStyles)
        : m_dwLayoutStyles(dwLayoutStyles), m_pCurLine(&m_Lines[0]) {}

        CFGAS_Break::~CFGAS_Break() = default;
        @@ -27,10 +27,10 @@
        line.Clear();
        }

        -void CFGAS_Break::SetLayoutStyles(uint32_t dwLayoutStyles) {
        +void CFGAS_Break::SetLayoutStyles(Mask<LayoutStyle> dwLayoutStyles) {
        m_dwLayoutStyles = dwLayoutStyles;
        - m_bSingleLine = (m_dwLayoutStyles & FX_LAYOUTSTYLE_SingleLine) != 0;
        - m_bCombText = (m_dwLayoutStyles & FX_LAYOUTSTYLE_CombText) != 0;
        + m_bSingleLine = !!(m_dwLayoutStyles & LayoutStyle::kSingleLine);
        + m_bCombText = !!(m_dwLayoutStyles & LayoutStyle::kCombText);
        }

        void CFGAS_Break::SetHorizontalScale(int32_t iScale) {
        diff --git a/xfa/fgas/layout/cfgas_break.h b/xfa/fgas/layout/cfgas_break.h
        index 5f38795..f6aa670 100644
        --- a/xfa/fgas/layout/cfgas_break.h
        +++ b/xfa/fgas/layout/cfgas_break.h
        @@ -9,28 +9,29 @@

        #include <stdint.h>

        +#include "core/fxcrt/mask.h"
        #include "core/fxcrt/retain_ptr.h"
        #include "core/fxcrt/unowned_ptr.h"
        #include "xfa/fgas/layout/cfgas_breakline.h"

        class CFGAS_GEFont;

        -enum FX_LAYOUTSTYLE {
        - FX_LAYOUTSTYLE_None = 0,
        - FX_LAYOUTSTYLE_Pagination = 0x01,
        - FX_LAYOUTSTYLE_ExpandTab = 0x10,
        - FX_LAYOUTSTYLE_SingleLine = 0x200,
        - FX_LAYOUTSTYLE_CombText = 0x400
        -};
        -
        class CFGAS_Break {
        public:
        + enum class LayoutStyle : uint8_t {
        + kNone = 0,
        + kPagination = 1 << 0,
        + kExpandTab = 1 << 1,
        + kSingleLine = 1 << 2,
        + kCombText = 1 << 3,
        + };
        +
        virtual ~CFGAS_Break();

        void Reset();

        - void SetLayoutStyles(uint32_t dwLayoutStyles);
        - uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; }
        + void SetLayoutStyles(Mask<LayoutStyle> dwLayoutStyles);
        + Mask<LayoutStyle> GetLayoutStyles() const { return m_dwLayoutStyles; }

        void SetFont(const RetainPtr<CFGAS_GEFont>& pFont);
        void SetFontSize(float fFontSize);
        @@ -65,7 +66,7 @@
        static const int kMinimumTabWidth;
        static const float kConversionFactor;

        - explicit CFGAS_Break(uint32_t dwLayoutStyles);
        + explicit CFGAS_Break(Mask<LayoutStyle> dwLayoutStyles);

        void SetBreakStatus();
        bool HasLine() const { return m_iReadyLineIndex >= 0; }
        @@ -75,8 +76,8 @@
        FX_CHARTYPE m_eCharType = FX_CHARTYPE::kUnknown;
        bool m_bSingleLine = false;
        bool m_bCombText = false;
        + Mask<LayoutStyle> m_dwLayoutStyles = LayoutStyle::kNone;
        uint32_t m_dwIdentity = 0;
        - uint32_t m_dwLayoutStyles = 0;
        int32_t m_iLineStart = 0;
        int32_t m_iLineWidth = 2000000;
        wchar_t m_wParagraphBreakChar = L'\n';
        diff --git a/xfa/fgas/layout/cfgas_rtfbreak.cpp b/xfa/fgas/layout/cfgas_rtfbreak.cpp
        index 87bbbea..401bdfa 100644
        --- a/xfa/fgas/layout/cfgas_rtfbreak.cpp
        +++ b/xfa/fgas/layout/cfgas_rtfbreak.cpp
        @@ -23,10 +23,10 @@
        #include "xfa/fgas/layout/fgas_arabic.h"
        #include "xfa/fgas/layout/fgas_linebreak.h"

        -CFGAS_RTFBreak::CFGAS_RTFBreak(uint32_t dwLayoutStyles)
        +CFGAS_RTFBreak::CFGAS_RTFBreak(Mask<LayoutStyle> dwLayoutStyles)
        : CFGAS_Break(dwLayoutStyles) {
        SetBreakStatus();
        - m_bPagination = !!(m_dwLayoutStyles & FX_LAYOUTSTYLE_Pagination);
        + m_bPagination = !!(m_dwLayoutStyles & LayoutStyle::kPagination);
        }

        CFGAS_RTFBreak::~CFGAS_RTFBreak() = default;
        @@ -150,7 +150,7 @@
        }

        void CFGAS_RTFBreak::AppendChar_Tab(CFGAS_Char* pCurChar) {
        - if (!(m_dwLayoutStyles & FX_LAYOUTSTYLE_ExpandTab))
        + if (!(m_dwLayoutStyles & LayoutStyle::kExpandTab))
        return;

        int32_t& iLineWidth = m_pCurLine->m_iWidth;
        diff --git a/xfa/fgas/layout/cfgas_rtfbreak.h b/xfa/fgas/layout/cfgas_rtfbreak.h
        index e944516..b1b52e9 100644
        --- a/xfa/fgas/layout/cfgas_rtfbreak.h
        +++ b/xfa/fgas/layout/cfgas_rtfbreak.h
        @@ -29,7 +29,7 @@
        Distributed
        };

        - explicit CFGAS_RTFBreak(uint32_t dwLayoutStyles);
        + explicit CFGAS_RTFBreak(Mask<LayoutStyle> dwLayoutStyles);
        ~CFGAS_RTFBreak() override;

        void SetLineStartPos(float fLinePos);
        diff --git a/xfa/fgas/layout/cfgas_rtfbreak_unittest.cpp b/xfa/fgas/layout/cfgas_rtfbreak_unittest.cpp
        index 4279146..5860add 100644
        --- a/xfa/fgas/layout/cfgas_rtfbreak_unittest.cpp
        +++ b/xfa/fgas/layout/cfgas_rtfbreak_unittest.cpp
        @@ -24,7 +24,8 @@
        ASSERT_TRUE(font_);
        }

        - std::unique_ptr<CFGAS_RTFBreak> CreateBreak(uint32_t layout_styles) {
        + std::unique_ptr<CFGAS_RTFBreak> CreateBreak(
        + Mask<CFGAS_Break::LayoutStyle> layout_styles) {
        auto rtf_break = std::make_unique<CFGAS_RTFBreak>(layout_styles);
        rtf_break->SetFont(font_);
        return rtf_break;
        @@ -38,8 +39,7 @@
        // and must be consumed before you get any more characters ....

        TEST_F(CFGAS_RTFBreakTest, AddChars) {
        - auto rtf_break = CreateBreak(FX_LAYOUTSTYLE_ExpandTab);
        -
        + auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
        WideString str(L"Input String.");
        for (wchar_t ch : str)
        EXPECT_EQ(CFGAS_Char::BreakType::kNone, rtf_break->AppendChar(ch));
        @@ -63,7 +63,7 @@
        }

        TEST_F(CFGAS_RTFBreakTest, ControlCharacters) {
        - auto rtf_break = CreateBreak(FX_LAYOUTSTYLE_ExpandTab);
        + auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
        EXPECT_EQ(CFGAS_Char::BreakType::kLine, rtf_break->AppendChar(L'\v'));
        EXPECT_EQ(CFGAS_Char::BreakType::kPage, rtf_break->AppendChar(L'\f'));
        EXPECT_EQ(CFGAS_Char::BreakType::kParagraph,
        @@ -75,7 +75,7 @@
        }

        TEST_F(CFGAS_RTFBreakTest, BidiLine) {
        - auto rtf_break = CreateBreak(FX_LAYOUTSTYLE_ExpandTab);
        + auto rtf_break = CreateBreak(CFGAS_Break::LayoutStyle::kExpandTab);
        rtf_break->SetLineBreakTolerance(1);
        rtf_break->SetFontSize(12);

        diff --git a/xfa/fgas/layout/cfgas_txtbreak.cpp b/xfa/fgas/layout/cfgas_txtbreak.cpp
        index aee9575..3845f11 100644
        --- a/xfa/fgas/layout/cfgas_txtbreak.cpp
        +++ b/xfa/fgas/layout/cfgas_txtbreak.cpp
        @@ -23,6 +23,12 @@

        namespace {

        +struct FX_FORMCHAR {
        + uint16_t wch;
        + uint16_t wForm;
        + int32_t iWidth;
        +};
        +
        bool IsCtrlCode(wchar_t wch) {
        FX_CHARTYPE dwRet = pdfium::unicode::GetCharType(wch);
        return dwRet == FX_CHARTYPE::kTab || dwRet == FX_CHARTYPE::kControl;
        @@ -30,7 +36,7 @@

        } // namespace

        -CFGAS_TxtBreak::CFGAS_TxtBreak() : CFGAS_Break(FX_LAYOUTSTYLE_None) {}
        +CFGAS_TxtBreak::CFGAS_TxtBreak() : CFGAS_Break(LayoutStyle::kNone) {}

        CFGAS_TxtBreak::~CFGAS_TxtBreak() = default;

        @@ -621,12 +627,6 @@
        pNextLine->m_iWidth = iWidth;
        }

        -struct FX_FORMCHAR {
        - uint16_t wch;
        - uint16_t wForm;
        - int32_t iWidth;
        -};
        -
        size_t CFGAS_TxtBreak::GetDisplayPos(const Run& run,
        TextCharPos* pCharPos) const {
        if (run.iLength < 1)
        @@ -637,7 +637,7 @@
        int32_t* pWidths = run.pWidths;
        int32_t iLength = run.iLength - 1;
        RetainPtr<CFGAS_GEFont> pFont = run.pFont;
        - uint32_t dwStyles = run.dwStyles;
        + Mask<LayoutStyle> dwStyles = run.dwStyles;
        CFX_RectF rtText(*run.pRect);
        bool bRTLPiece = (run.dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0;
        float fFontSize = run.fFontSize;
        @@ -827,7 +827,7 @@
        if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) {
        pCharPos->m_Origin = CFX_PointF(fX, fY);

        - if ((dwStyles & FX_LAYOUTSTYLE_CombText) != 0) {
        + if (!!(dwStyles & LayoutStyle::kCombText)) {
        int32_t iFormWidth = pFont->GetCharWidth(wForm).value_or(iCharWidth);
        float fOffset = fFontSize * (iCharWidth - iFormWidth) / 2000.0f;
        pCharPos->m_Origin.x += fOffset;
        @@ -893,7 +893,7 @@
        CFX_RectF rect(*run.pRect);
        float fFontSize = run.fFontSize;
        bool bRTLPiece = !!(run.dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel);
        - bool bSingleLine = !!(run.dwStyles & FX_LAYOUTSTYLE_SingleLine);
        + bool bSingleLine = !!(run.dwStyles & LayoutStyle::kSingleLine);
        float fStart = bRTLPiece ? rect.right() : rect.left;

        std::vector<CFX_RectF> rtArray(iLength);
        diff --git a/xfa/fgas/layout/cfgas_txtbreak.h b/xfa/fgas/layout/cfgas_txtbreak.h
        index ecb397b..283e8c6 100644
        --- a/xfa/fgas/layout/cfgas_txtbreak.h
        +++ b/xfa/fgas/layout/cfgas_txtbreak.h
        @@ -56,7 +56,7 @@
        int32_t iLength = 0;
        RetainPtr<CFGAS_GEFont> pFont;
        float fFontSize = 12.0f;
        - uint32_t dwStyles = 0;
        + Mask<LayoutStyle> dwStyles = LayoutStyle::kNone;
        int32_t iHorizontalScale = 100;
        int32_t iVerticalScale = 100;
        uint32_t dwCharStyles = 0;
        diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
        index 7fef9ea..bc29013 100644
        --- a/xfa/fxfa/cxfa_textlayout.cpp
        +++ b/xfa/fxfa/cxfa_textlayout.cpp
        @@ -148,9 +148,9 @@
        }

        std::unique_ptr<CFGAS_RTFBreak> CXFA_TextLayout::CreateBreak(bool bDefault) {
        - uint32_t dwStyle = FX_LAYOUTSTYLE_ExpandTab;
        + Mask<CFGAS_Break::LayoutStyle> dwStyle = CFGAS_Break::LayoutStyle::kExpandTab;
        if (!bDefault)
        - dwStyle |= FX_LAYOUTSTYLE_Pagination;
        + dwStyle |= CFGAS_Break::LayoutStyle::kPagination;

        auto pBreak = std::make_unique<CFGAS_RTFBreak>(dwStyle);
        pBreak->SetLineBreakTolerance(1);

        To view, visit change 84470. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I7f2c903cfec8fc36bb1f6ae925d3bb4378b5c140
        Gerrit-Change-Number: 84470
        Gerrit-PatchSet: 2
        Gerrit-Owner: Tom Sepez <tse...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages