Add GetBreakPropertyFromProp() and GetLineBreakTypeFromPair().
Precursor to fixing table size issue.
No functional change, just document current state of affairs.
Change-Id: I82300f96dd39ad400dbecccb9b9a88acfde5c5f6
Reviewed-on: https://pdfium-review.googlesource.com/c/47890
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_unicode.h b/core/fxcrt/fx_unicode.h
index b1c1b0d..9611011 100644
--- a/core/fxcrt/fx_unicode.h
+++ b/core/fxcrt/fx_unicode.h
@@ -7,7 +7,7 @@
#ifndef CORE_FXCRT_FX_UNICODE_H_
#define CORE_FXCRT_FX_UNICODE_H_
-#include <stdint.h>
+#include "core/fxcrt/fx_system.h"
uint32_t FX_GetUnicodeProperties(wchar_t wch);
wchar_t FX_GetMirrorChar(wchar_t wch);
@@ -16,7 +16,7 @@
// As defined in http://www.unicode.org/reports/tr14
constexpr uint8_t kBreakPropertySpace = 35;
-constexpr uint8_t kBreakPropertyTB = 37; // Don't know what this is ...
+constexpr uint8_t kBreakPropertyTB = 37; // Highest, don't know what this is.
constexpr uint32_t FX_CHARTYPEBITS = 11;
constexpr uint32_t FX_CHARTYPEBITSMASK = 0xF << FX_CHARTYPEBITS;
@@ -41,6 +41,13 @@
return static_cast<FX_CHARTYPE>(prop & FX_CHARTYPEBITSMASK);
}
+inline uint32_t GetBreakPropertyFromProp(uint32_t prop) {
+ // Analagous to ULineBreak in icu's uchar.h, but permuted order, and a
+ // subset lacking some more recent additions.
+ ASSERT((prop & 0x3f) <= kBreakPropertyTB);
+ return prop & 0x3f;
+}
+
wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps);
#endif // PDF_ENABLE_XFA
diff --git a/xfa/fgas/layout/cfx_linebreak.h b/xfa/fgas/layout/cfx_linebreak.h
index ca2e4b5..ca3293f 100644
--- a/xfa/fgas/layout/cfx_linebreak.h
+++ b/xfa/fgas/layout/cfx_linebreak.h
@@ -8,6 +8,7 @@
#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,
@@ -19,6 +20,14 @@
FX_LBT_HANGUL_SPACE_BRK = 0x6F,
};
+// TODO(tsepez): the dimensions of this table are wrong, should be 38x38.
extern const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[64][32];
+inline FX_LINEBREAKTYPE GetLineBreakTypeFromPair(uint32_t curr_char_break,
+ uint32_t next_char_break) {
+ ASSERT(curr_char_break <= kBreakPropertyTB);
+ ASSERT(next_char_break <= kBreakPropertyTB);
+ return gs_FX_LineBreak_PairTable[curr_char_break][next_char_break];
+}
+
#endif // XFA_FGAS_LAYOUT_CFX_LINEBREAK_H_
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 9dce8d7..70a5756 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -609,7 +609,7 @@
pCur->m_nBreakType = FX_LBT_UNKNOWN;
uint32_t nCodeProp = pCur->char_props();
- uint32_t nNext = nCodeProp & 0x003F;
+ uint32_t nNext = GetBreakPropertyFromProp(nCodeProp);
int32_t iCharWidth = pCur->m_iCharWidth;
if (iCharWidth > 0)
*pEndPos -= iCharWidth;
@@ -617,21 +617,20 @@
while (iLength >= 0) {
pCur = pCharArray + iLength;
nCodeProp = pCur->char_props();
- uint32_t nCur = nCodeProp & 0x003F;
+ uint32_t nCur = GetBreakPropertyFromProp(nCodeProp);
bool bNeedBreak = false;
FX_LINEBREAKTYPE eType;
if (nCur == kBreakPropertyTB) {
bNeedBreak = true;
- eType = nNext == kBreakPropertyTB
- ? FX_LBT_PROHIBITED_BRK
- : gs_FX_LineBreak_PairTable[nCur][nNext];
+ eType = nNext == kBreakPropertyTB ? FX_LBT_PROHIBITED_BRK
+ : GetLineBreakTypeFromPair(nCur, nNext);
} else {
if (nCur == kBreakPropertySpace)
bNeedBreak = true;
eType = nNext == kBreakPropertySpace
? FX_LBT_PROHIBITED_BRK
- : gs_FX_LineBreak_PairTable[nCur][nNext];
+ : GetLineBreakTypeFromPair(nCur, nNext);
}
if (bAllChars)
pCur->m_nBreakType = eType;
@@ -656,7 +655,7 @@
if (iCharWidth > 0)
*pEndPos -= iCharWidth;
}
- nNext = nCodeProp & 0x003F;
+ nNext = GetBreakPropertyFromProp(nCodeProp);
--iLength;
}
if (bOnlyBrk)
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index d861058..9d14305 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -554,7 +554,7 @@
pCur->m_nBreakType = FX_LBT_UNKNOWN;
nCodeProp = pCur->char_props();
- nNext = nCodeProp & 0x003F;
+ nNext = GetBreakPropertyFromProp(nCodeProp);
int32_t iCharWidth = pCur->m_iCharWidth;
if (iCharWidth > 0)
*pEndPos -= iCharWidth;
@@ -562,11 +562,11 @@
while (iLength >= 0) {
pCur = &chars[iLength];
nCodeProp = pCur->char_props();
- nCur = nCodeProp & 0x003F;
+ nCur = GetBreakPropertyFromProp(nCodeProp);
if (nNext == kBreakPropertySpace)
eType = FX_LBT_PROHIBITED_BRK;
else
- eType = gs_FX_LineBreak_PairTable[nCur][nNext];
+ eType = GetLineBreakTypeFromPair(nCur, nNext);
if (bAllChars)
pCur->m_nBreakType = static_cast<uint8_t>(eType);
if (!bOnlyBrk) {
@@ -590,7 +590,7 @@
if (iCharWidth > 0)
*pEndPos -= iCharWidth;
}
- nNext = nCodeProp & 0x003F;
+ nNext = GetBreakPropertyFromProp(nCodeProp);
iLength--;
}
if (bOnlyBrk)