diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-11 23:27:19 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-11 23:27:19 +0000 |
commit | 94f3ca931552ba76d1b216020633829e1a07b212 (patch) | |
tree | 6b27106784f47e4c44cbc2cacae828c6b56a22b7 /fxjs | |
parent | a1188905b85a84d950f94df0f229b9f1d5784c61 (diff) | |
download | pdfium-94f3ca931552ba76d1b216020633829e1a07b212.tar.xz |
Fix some nits in CJS_Document helpers.
Change-Id: Iad2eaf53fcca2d4eee92760cdbd6da2869695d56
Reviewed-on: https://pdfium-review.googlesource.com/c/43831
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjs_document.cpp | 34 |
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++; } |