From 94f3ca931552ba76d1b216020633829e1a07b212 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 11 Oct 2018 23:27:19 +0000 Subject: Fix some nits in CJS_Document helpers. Change-Id: Iad2eaf53fcca2d4eee92760cdbd6da2869695d56 Reviewed-on: https://pdfium-review.googlesource.com/c/43831 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- fxjs/cjs_document.cpp | 34 +++++++++++++++------------------- 1 file 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++; } -- cgit v1.2.3