Make FX_LINEBREAK an enum class.
Then use it in CFX_Char in place of uint8_t. In turn, this forces
fx_linebreak.{cpp,h} to move to fxcrt/. Then conditionalize its
use in CFX_Char based on XFA.
Change-Id: I0818c09db135d86685eb018ee6eda4faf9b395f6
Reviewed-on: https://pdfium-review.googlesource.com/c/48195
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index 3b17d00..a649346 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -124,6 +124,8 @@
"cfx_decimal.h",
"fx_arabic.cpp",
"fx_arabic.h",
+ "fx_linebreak.cpp",
+ "fx_linebreak.h",
"locale_iface.h",
]
}
diff --git a/core/fxcrt/cfx_char.h b/core/fxcrt/cfx_char.h
index 8ccdad4..5a5268f 100644
--- a/core/fxcrt/cfx_char.h
+++ b/core/fxcrt/cfx_char.h
@@ -9,6 +9,7 @@
#include <stdint.h>
+#include "core/fxcrt/fx_linebreak.h"
#include "core/fxcrt/fx_unicode.h"
#include "core/fxcrt/retain_ptr.h"
@@ -31,7 +32,7 @@
CFX_BreakType m_dwStatus = CFX_BreakType::None;
FX_BIDICLASS m_iBidiClass = FX_BIDICLASS::kON;
- uint8_t m_nBreakType = 0;
+ FX_LINEBREAKTYPE m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
uint32_t m_dwCharStyles = 0;
int32_t m_iCharWidth = 0;
uint16_t m_iBidiLevel = 0;
diff --git a/xfa/fgas/layout/cfx_linebreak.cpp b/core/fxcrt/fx_linebreak.cpp
similarity index 97%
rename from xfa/fgas/layout/cfx_linebreak.cpp
rename to core/fxcrt/fx_linebreak.cpp
index 52b8ba8..48b6633 100644
--- a/xfa/fgas/layout/cfx_linebreak.cpp
+++ b/core/fxcrt/fx_linebreak.cpp
@@ -4,20 +4,20 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "xfa/fgas/layout/cfx_linebreak.h"
+#include "core/fxcrt/fx_linebreak.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_unicode.h"
namespace {
-#define FX_LBUN FX_LBT_UNKNOWN
-#define FX_LBDB FX_LBT_DIRECT_BRK
-#define FX_LBIB FX_LBT_INDIRECT_BRK
-#define FX_LBCB FX_LBT_COM_INDIRECT_BRK
-#define FX_LBCP FX_LBT_COM_PROHIBITED_BRK
-#define FX_LBPB FX_LBT_PROHIBITED_BRK
-#define FX_LBHS FX_LBT_HANGUL_SPACE_BRK
+#define FX_LBUN FX_LINEBREAKTYPE::kUNKNOWN
+#define FX_LBDB FX_LINEBREAKTYPE::kDIRECT_BRK
+#define FX_LBIB FX_LINEBREAKTYPE::kINDIRECT_BRK
+#define FX_LBCB FX_LINEBREAKTYPE::kCOM_INDIRECT_BRK
+#define FX_LBCP FX_LINEBREAKTYPE::kCOM_PROHIBITED_BRK
+#define FX_LBPB FX_LINEBREAKTYPE::kPROHIBITED_BRK
+#define FX_LBHS FX_LINEBREAKTYPE::kHANGUL_SPACE_BRK
const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[38][38] = {
{FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB,
diff --git a/core/fxcrt/fx_linebreak.h b/core/fxcrt/fx_linebreak.h
new file mode 100644
index 0000000..38efc80
--- /dev/null
+++ b/core/fxcrt/fx_linebreak.h
@@ -0,0 +1,26 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCRT_FX_LINEBREAK_H_
+#define CORE_FXCRT_FX_LINEBREAK_H_
+
+#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/fx_unicode.h"
+
+enum class FX_LINEBREAKTYPE : uint8_t {
+ kUNKNOWN = 0x00,
+ kDIRECT_BRK = 0x1A,
+ kINDIRECT_BRK = 0x2B,
+ kCOM_INDIRECT_BRK = 0x3C,
+ kCOM_PROHIBITED_BRK = 0x4D,
+ kPROHIBITED_BRK = 0x5E,
+ kHANGUL_SPACE_BRK = 0x6F,
+};
+
+FX_LINEBREAKTYPE GetLineBreakTypeFromPair(FX_BREAKPROPERTY curr_char,
+ FX_BREAKPROPERTY next_char);
+
+#endif // CORE_FXCRT_FX_LINEBREAK_H_
diff --git a/xfa/fgas/layout/BUILD.gn b/xfa/fgas/layout/BUILD.gn
index 41bd375..4411101 100644
--- a/xfa/fgas/layout/BUILD.gn
+++ b/xfa/fgas/layout/BUILD.gn
@@ -16,8 +16,6 @@
"cfx_breakline.h",
"cfx_breakpiece.cpp",
"cfx_breakpiece.h",
- "cfx_linebreak.cpp",
- "cfx_linebreak.h",
"cfx_rtfbreak.cpp",
"cfx_rtfbreak.h",
"cfx_txtbreak.cpp",
diff --git a/xfa/fgas/layout/cfx_linebreak.h b/xfa/fgas/layout/cfx_linebreak.h
deleted file mode 100644
index cd731a5..0000000
--- a/xfa/fgas/layout/cfx_linebreak.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FGAS_LAYOUT_CFX_LINEBREAK_H_
-#define XFA_FGAS_LAYOUT_CFX_LINEBREAK_H_
-
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/fx_unicode.h"
-
-enum FX_LINEBREAKTYPE : uint8_t {
- FX_LBT_UNKNOWN = 0x00,
- FX_LBT_DIRECT_BRK = 0x1A,
- FX_LBT_INDIRECT_BRK = 0x2B,
- FX_LBT_COM_INDIRECT_BRK = 0x3C,
- FX_LBT_COM_PROHIBITED_BRK = 0x4D,
- FX_LBT_PROHIBITED_BRK = 0x5E,
- FX_LBT_HANGUL_SPACE_BRK = 0x6F,
-};
-
-FX_LINEBREAKTYPE GetLineBreakTypeFromPair(FX_BREAKPROPERTY curr_char,
- FX_BREAKPROPERTY next_char);
-
-#endif // XFA_FGAS_LAYOUT_CFX_LINEBREAK_H_
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index e446626..61fb9d9 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -10,11 +10,11 @@
#include "core/fxcrt/fx_arabic.h"
#include "core/fxcrt/fx_bidi.h"
+#include "core/fxcrt/fx_linebreak.h"
#include "core/fxge/cfx_renderdevice.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/stl_util.h"
#include "xfa/fgas/font/cfgas_gefont.h"
-#include "xfa/fgas/layout/cfx_linebreak.h"
CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles)
: CFX_Break(dwLayoutStyles),
@@ -518,7 +518,7 @@
int32_t j = bArabic ? 0 : ttp.m_iChars - 1;
while (j > -1 && j < ttp.m_iChars) {
const CFX_Char* tc = ttp.GetChar(j);
- if (tc->m_nBreakType == FX_LBT_DIRECT_BRK)
+ if (tc->m_eLineBreakType == FX_LINEBREAKTYPE::kDIRECT_BRK)
++iGapChars;
if (!bFind || !bAllChars) {
@@ -556,9 +556,10 @@
for (int32_t j = 0; j < ttp.m_iChars; ++j) {
CFX_Char* tc = ttp.GetChar(j);
- if (tc->m_nBreakType != FX_LBT_DIRECT_BRK || tc->m_iCharWidth < 0)
+ if (tc->m_eLineBreakType != FX_LINEBREAKTYPE::kDIRECT_BRK ||
+ tc->m_iCharWidth < 0) {
continue;
-
+ }
int32_t k = iOffset / iGapChars;
tc->m_iCharWidth += k;
ttp.m_iWidth += k;
@@ -606,7 +607,7 @@
CFX_Char* pCur = pCharArray + iLength;
--iLength;
if (bAllChars)
- pCur->m_nBreakType = FX_LBT_UNKNOWN;
+ pCur->m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
FX_BREAKPROPERTY nNext = FX_GetBreakProperty(pCur->char_code());
int32_t iCharWidth = pCur->m_iCharWidth;
@@ -621,28 +622,28 @@
if (nCur == FX_BREAKPROPERTY::kTB) {
bNeedBreak = true;
eType = nNext == FX_BREAKPROPERTY::kTB
- ? FX_LBT_PROHIBITED_BRK
+ ? FX_LINEBREAKTYPE::kPROHIBITED_BRK
: GetLineBreakTypeFromPair(nCur, nNext);
} else {
if (nCur == FX_BREAKPROPERTY::kSP)
bNeedBreak = true;
eType = nNext == FX_BREAKPROPERTY::kSP
- ? FX_LBT_PROHIBITED_BRK
+ ? FX_LINEBREAKTYPE::kPROHIBITED_BRK
: GetLineBreakTypeFromPair(nCur, nNext);
}
if (bAllChars)
- pCur->m_nBreakType = eType;
+ pCur->m_eLineBreakType = eType;
if (!bOnlyBrk) {
iCharWidth = pCur->m_iCharWidth;
if (*pEndPos <= m_iLineWidth || bNeedBreak) {
- if (eType == FX_LBT_DIRECT_BRK && iBreak < 0) {
+ if (eType == FX_LINEBREAKTYPE::kDIRECT_BRK && iBreak < 0) {
iBreak = iLength;
iBreakPos = *pEndPos;
if (!bAllChars)
return iLength;
- } else if (eType == FX_LBT_INDIRECT_BRK && iIndirect < 0) {
+ } else if (eType == FX_LINEBREAKTYPE::kINDIRECT_BRK && iIndirect < 0) {
iIndirect = iLength;
iIndirectPos = *pEndPos;
}
@@ -693,7 +694,7 @@
++iCharPos;
if (iCharPos >= pdfium::CollectionSize<int32_t>(pCurLine->m_LineChars)) {
pNextLine->Clear();
- curChars[iCharPos - 1].m_nBreakType = FX_LBT_UNKNOWN;
+ curChars[iCharPos - 1].m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
return;
}
@@ -703,7 +704,7 @@
pNextLine->m_iStart = pCurLine->m_iStart;
pNextLine->m_iWidth = pCurLine->GetLineEnd() - iEndPos;
pCurLine->m_iWidth = iEndPos;
- curChars[iCharPos - 1].m_nBreakType = FX_LBT_UNKNOWN;
+ curChars[iCharPos - 1].m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
for (size_t i = 0; i < pNextLine->m_LineChars.size(); ++i) {
if (pNextLine->m_LineChars[i].GetCharType() >= FX_CHARTYPE::kArabicAlef) {
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index 2ed51bd..d5a6cb4 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -10,10 +10,10 @@
#include "core/fxcrt/fx_arabic.h"
#include "core/fxcrt/fx_bidi.h"
+#include "core/fxcrt/fx_linebreak.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/cfde_texteditengine.h"
#include "xfa/fgas/font/cfgas_gefont.h"
-#include "xfa/fgas/layout/cfx_linebreak.h"
namespace {
@@ -425,7 +425,7 @@
int32_t j = bArabic ? 0 : ttp.m_iChars - 1;
while (j > -1 && j < ttp.m_iChars) {
const CFX_Char* pTC = ttp.GetChar(j);
- if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK)
+ if (pTC->m_eLineBreakType == FX_LINEBREAKTYPE::kDIRECT_BRK)
iGapChars++;
if (!bFind || !bAllChars) {
FX_CHARTYPE chartype = pTC->GetCharType();
@@ -458,9 +458,10 @@
for (int32_t j = 0; j < ttp.m_iChars && iGapChars > 0; j++, iGapChars--) {
CFX_Char* pTC = ttp.GetChar(j);
- if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0)
+ if (pTC->m_eLineBreakType != FX_LINEBREAKTYPE::kDIRECT_BRK ||
+ pTC->m_iCharWidth < 0) {
continue;
-
+ }
int32_t k = iOffset / iGapChars;
pTC->m_iCharWidth += k;
ttp.m_iWidth += k;
@@ -551,7 +552,7 @@
FX_BREAKPROPERTY nNext;
CFX_Char* pCur = &chars[iLength--];
if (bAllChars)
- pCur->m_nBreakType = FX_LBT_UNKNOWN;
+ pCur->m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
nNext = FX_GetBreakProperty(pCur->char_code());
int32_t iCharWidth = pCur->m_iCharWidth;
@@ -562,20 +563,20 @@
pCur = &chars[iLength];
nCur = FX_GetBreakProperty(pCur->char_code());
if (nNext == FX_BREAKPROPERTY::kSP)
- eType = FX_LBT_PROHIBITED_BRK;
+ eType = FX_LINEBREAKTYPE::kPROHIBITED_BRK;
else
eType = GetLineBreakTypeFromPair(nCur, nNext);
if (bAllChars)
- pCur->m_nBreakType = static_cast<uint8_t>(eType);
+ pCur->m_eLineBreakType = eType;
if (!bOnlyBrk) {
if (m_bSingleLine || *pEndPos <= m_iLineWidth ||
nCur == FX_BREAKPROPERTY::kSP) {
- if (eType == FX_LBT_DIRECT_BRK && iBreak < 0) {
+ if (eType == FX_LINEBREAKTYPE::kDIRECT_BRK && iBreak < 0) {
iBreak = iLength;
iBreakPos = *pEndPos;
if (!bAllChars)
return iLength;
- } else if (eType == FX_LBT_INDIRECT_BRK && iIndirect < 0) {
+ } else if (eType == FX_LINEBREAKTYPE::kINDIRECT_BRK && iIndirect < 0) {
iIndirect = iLength;
iIndirectPos = *pEndPos;
}
@@ -627,7 +628,7 @@
if (iCharPos >= pdfium::CollectionSize<int32_t>(pCurLine->m_LineChars)) {
pNextLine->Clear();
CFX_Char* pTC = &curChars[iCharPos - 1];
- pTC->m_nBreakType = FX_LBT_UNKNOWN;
+ pTC->m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
return;
}
@@ -636,7 +637,7 @@
curChars.erase(curChars.begin() + iCharPos, curChars.end());
pCurLine->m_iWidth = iEndPos;
CFX_Char* pTC = &curChars[iCharPos - 1];
- pTC->m_nBreakType = FX_LBT_UNKNOWN;
+ pTC->m_eLineBreakType = FX_LINEBREAKTYPE::kUNKNOWN;
int32_t iWidth = 0;
for (size_t i = 0; i < pNextLine->m_LineChars.size(); ++i) {
if (pNextLine->m_LineChars[i].GetCharType() >= FX_CHARTYPE::kArabicAlef) {