summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cjs_document.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 6e2f2da6c6..7f81a37f72 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -32,31 +32,29 @@ namespace {
#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
-int CountWords(CPDF_TextObject* pTextObj) {
- if (!pTextObj)
- return 0;
-
+int CountWords(const CPDF_TextObject* pTextObj) {
CPDF_Font* pFont = pTextObj->GetFont();
if (!pFont)
return 0;
- bool bIsLatin = false;
+ bool bInLatinWord = false;
int nWords = 0;
for (size_t i = 0, sz = pTextObj->CountChars(); i < sz; ++i) {
uint32_t charcode = CPDF_Font::kInvalidCharCode;
- float kerning;
+ float unused_kerning;
- pTextObj->GetCharInfo(i, &charcode, &kerning);
+ pTextObj->GetCharInfo(i, &charcode, &unused_kerning);
WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
uint16_t unicode = 0;
if (swUnicode.GetLength() > 0)
unicode = swUnicode[0];
- if (ISLATINWORD(unicode) && bIsLatin)
+ bool bIsLatin = ISLATINWORD(unicode);
+ if (bIsLatin && bInLatinWord)
continue;
- bIsLatin = ISLATINWORD(unicode);
+ bInLatinWord = bIsLatin;
if (unicode != 0x20)
nWords++;
}
@@ -64,30 +62,28 @@ int CountWords(CPDF_TextObject* pTextObj) {
return nWords;
}
-WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex) {
- WideString swRet;
-
+WideString GetObjWordStr(const CPDF_TextObject* pTextObj, int nWordIndex) {
CPDF_Font* pFont = pTextObj->GetFont();
if (!pFont)
return L"";
+ WideString swRet;
int nWords = 0;
- bool bIsLatin = false;
-
+ bool bInLatinWord = false;
for (size_t i = 0, sz = pTextObj->CountChars(); i < sz; ++i) {
uint32_t charcode = CPDF_Font::kInvalidCharCode;
- float kerning;
+ float unused_kerning;
- pTextObj->GetCharInfo(i, &charcode, &kerning);
+ pTextObj->GetCharInfo(i, &charcode, &unused_kerning);
WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
uint16_t unicode = 0;
if (swUnicode.GetLength() > 0)
unicode = swUnicode[0];
- if (ISLATINWORD(unicode) && bIsLatin) {
- } else {
- bIsLatin = ISLATINWORD(unicode);
+ bool bIsLatin = ISLATINWORD(unicode);
+ if (!bIsLatin || !bInLatinWord) {
+ bInLatinWord = bIsLatin;
if (unicode != 0x20)
nWords++;
}