summaryrefslogtreecommitdiff
path: root/core/fpdfapi/font
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-09 20:33:45 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-09 20:33:45 +0000
commite372ad7333bdd6bb0c579cf074843ef0c6f3414f (patch)
tree9928344d0def23d3fb070713a88947aceb6b5c71 /core/fpdfapi/font
parent0d8e530fbf898c1ba1ba4d3d91aa17e3fd4d8317 (diff)
downloadpdfium-e372ad7333bdd6bb0c579cf074843ef0c6f3414f.tar.xz
Use ByteStringView / pdfium::span in CPDF font as appropriate.chromium/3393
Change-Id: I92c7ba605bf95a9023ad046b8dddebe0a0592802 Reviewed-on: https://pdfium-review.googlesource.com/29992 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/font')
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp11
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.h7
-rw-r--r--core/fpdfapi/font/cpdf_cmap.cpp32
-rw-r--r--core/fpdfapi/font/cpdf_cmap.h4
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp30
-rw-r--r--core/fpdfapi/font/cpdf_font.h9
6 files changed, 43 insertions, 50 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 7de4d7cd82..4d3ffdf41f 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -751,18 +751,17 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
return pdata[0] * 256 + pdata[1];
}
-uint32_t CPDF_CIDFont::GetNextChar(const char* pString,
- int nStrLen,
- int& offset) const {
- return m_pCMap->GetNextChar(pString, nStrLen, offset);
+uint32_t CPDF_CIDFont::GetNextChar(const ByteStringView& pString,
+ size_t& offset) const {
+ return m_pCMap->GetNextChar(pString, offset);
}
int CPDF_CIDFont::GetCharSize(uint32_t charcode) const {
return m_pCMap->GetCharSize(charcode);
}
-int CPDF_CIDFont::CountChar(const char* pString, int size) const {
- return m_pCMap->CountChar(pString, size);
+size_t CPDF_CIDFont::CountChar(const ByteStringView& pString) const {
+ return m_pCMap->CountChar(pString);
}
int CPDF_CIDFont::AppendChar(char* str, uint32_t charcode) const {
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h
index 0bf5f7ace1..fe2e2fed4e 100644
--- a/core/fpdfapi/font/cpdf_cidfont.h
+++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -46,10 +46,9 @@ class CPDF_CIDFont : public CPDF_Font {
int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
uint32_t GetCharWidthF(uint32_t charcode) override;
FX_RECT GetCharBBox(uint32_t charcode) override;
- uint32_t GetNextChar(const char* pString,
- int nStrLen,
- int& offset) const override;
- int CountChar(const char* pString, int size) const override;
+ uint32_t GetNextChar(const ByteStringView& pString,
+ size_t& offset) const override;
+ size_t CountChar(const ByteStringView& pString) const override;
int AppendChar(char* str, uint32_t charcode) const override;
bool IsVertWriting() const override;
bool IsUnicodeCompatible() const override;
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index 81ad63344c..8e46a75112 100644
--- a/core/fpdfapi/font/cpdf_cmap.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -337,10 +337,9 @@ uint16_t CPDF_CMap::CIDFromCharCode(uint32_t charcode) const {
return it->m_StartCID + charcode - it->m_StartCode;
}
-uint32_t CPDF_CMap::GetNextChar(const char* pString,
- int nStrLen,
- int& offset) const {
- auto* pBytes = reinterpret_cast<const uint8_t*>(pString);
+uint32_t CPDF_CMap::GetNextChar(const ByteStringView& pString,
+ size_t& offset) const {
+ auto pBytes = pString.span();
switch (m_CodingScheme) {
case OneByte: {
return pBytes[offset++];
@@ -370,7 +369,7 @@ uint32_t CPDF_CMap::GetNextChar(const char* pString,
charcode = (charcode << 8) + codes[i];
return charcode;
}
- if (char_size == 4 || offset == nStrLen)
+ if (char_size == 4 || offset == pBytes.size())
return 0;
codes[char_size++] = pBytes[offset++];
}
@@ -402,33 +401,32 @@ int CPDF_CMap::GetCharSize(uint32_t charcode) const {
return 1;
}
-int CPDF_CMap::CountChar(const char* pString, int size) const {
+size_t CPDF_CMap::CountChar(const ByteStringView& pString) const {
switch (m_CodingScheme) {
case OneByte:
- return size;
+ return pString.GetLength();
case TwoBytes:
- return (size + 1) / 2;
+ return (pString.GetLength() + 1) / 2;
case MixedTwoBytes: {
- int count = 0;
- for (int i = 0; i < size; i++) {
+ size_t count = 0;
+ for (size_t i = 0; i < pString.GetLength(); i++) {
count++;
- if (m_MixedTwoByteLeadingBytes[reinterpret_cast<const uint8_t*>(
- pString)[i]]) {
+ if (m_MixedTwoByteLeadingBytes[pString[i]])
i++;
- }
}
return count;
}
case MixedFourBytes: {
- int count = 0, offset = 0;
- while (offset < size) {
- GetNextChar(pString, size, offset);
+ size_t count = 0;
+ size_t offset = 0;
+ while (offset < pString.GetLength()) {
+ GetNextChar(pString, offset);
count++;
}
return count;
}
}
- return size;
+ return pString.GetLength();
}
int CPDF_CMap::AppendChar(char* str, uint32_t charcode) const {
diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h
index c6fdcae17b..96ccf02c0b 100644
--- a/core/fpdfapi/font/cpdf_cmap.h
+++ b/core/fpdfapi/font/cpdf_cmap.h
@@ -62,8 +62,8 @@ class CPDF_CMap : public Retainable {
uint16_t CIDFromCharCode(uint32_t charcode) const;
int GetCharSize(uint32_t charcode) const;
- uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const;
- int CountChar(const char* pString, int size) const;
+ uint32_t GetNextChar(const ByteStringView& pString, size_t& offset) const;
+ size_t CountChar(const ByteStringView& pString) const;
int AppendChar(char* str, uint32_t charcode) const;
void SetVertical(bool vert) { m_bVertical = vert; }
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 013cdded20..f636e9397a 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -122,8 +122,8 @@ bool CPDF_Font::IsUnicodeCompatible() const {
return false;
}
-int CPDF_Font::CountChar(const char* pString, int size) const {
- return size;
+size_t CPDF_Font::CountChar(const ByteStringView& pString) const {
+ return pString.GetLength();
}
int CPDF_Font::GlyphFromCharCodeExt(uint32_t charcode) {
@@ -278,20 +278,18 @@ void CPDF_Font::CheckFontMetrics() {
void CPDF_Font::LoadUnicodeMap() const {
m_bToUnicodeLoaded = true;
CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode");
- if (!pStream) {
+ if (!pStream)
return;
- }
+
m_pToUnicodeMap = pdfium::MakeUnique<CPDF_ToUnicodeMap>();
m_pToUnicodeMap->Load(pStream);
}
-uint32_t CPDF_Font::GetStringWidth(const char* pString, int size) {
- int offset = 0;
+uint32_t CPDF_Font::GetStringWidth(const ByteStringView& pString) {
+ size_t offset = 0;
uint32_t width = 0;
- while (offset < size) {
- uint32_t charcode = GetNextChar(pString, size, offset);
- width += GetCharWidthF(charcode);
- }
+ while (offset < pString.GetLength())
+ width += GetCharWidthF(GetNextChar(pString, offset));
return width;
}
@@ -346,13 +344,13 @@ std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc,
return pFont->Load() ? std::move(pFont) : nullptr;
}
-uint32_t CPDF_Font::GetNextChar(const char* pString,
- int nStrLen,
- int& offset) const {
- if (offset < 0 || nStrLen < 1) {
+uint32_t CPDF_Font::GetNextChar(const ByteStringView& pString,
+ size_t& offset) const {
+ if (pString.IsEmpty())
return 0;
- }
- uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1];
+
+ uint8_t ch = offset < pString.GetLength() ? pString[offset++]
+ : pString[pString.GetLength() - 1];
return static_cast<uint32_t>(ch);
}
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index db99efdd1b..588fb66163 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -53,10 +53,9 @@ class CPDF_Font {
virtual bool IsVertWriting() const;
virtual bool IsUnicodeCompatible() const;
- virtual uint32_t GetNextChar(const char* pString,
- int nStrLen,
- int& offset) const;
- virtual int CountChar(const char* pString, int size) const;
+ virtual uint32_t GetNextChar(const ByteStringView& pString,
+ size_t& offset) const;
+ virtual size_t CountChar(const ByteStringView& pString) const;
virtual int AppendChar(char* buf, uint32_t charcode) const;
virtual int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) = 0;
virtual int GlyphFromCharCodeExt(uint32_t charcode);
@@ -75,7 +74,7 @@ class CPDF_Font {
void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; }
int GetTypeAscent() const { return m_Ascent; }
int GetTypeDescent() const { return m_Descent; }
- uint32_t GetStringWidth(const char* pString, int size);
+ uint32_t GetStringWidth(const ByteStringView& pString);
uint32_t FallbackFontFromCharcode(uint32_t charcode);
int FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode);