| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" | 9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" |
| 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 FX_Free(m_pCharCodes); | 21 FX_Free(m_pCharCodes); |
| 22 } | 22 } |
| 23 FX_Free(m_pCharPos); | 23 FX_Free(m_pCharPos); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { | 26 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { |
| 27 pInfo->m_CharCode = | 27 pInfo->m_CharCode = |
| 28 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; | 28 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; |
| 29 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; | 29 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; |
| 30 pInfo->m_OriginY = 0; | 30 pInfo->m_OriginY = 0; |
| 31 if (pInfo->m_CharCode == -1) { | 31 if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode) { |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 CPDF_Font* pFont = m_TextState.GetFont(); | 34 CPDF_Font* pFont = m_TextState.GetFont(); |
| 35 if (!pFont->IsCIDFont()) { | 35 if (!pFont->IsCIDFont()) { |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 if (!pFont->AsCIDFont()->IsVertWriting()) { | 38 if (!pFont->AsCIDFont()->IsVertWriting()) { |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); | 41 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); |
| 42 pInfo->m_OriginY = pInfo->m_OriginX; | 42 pInfo->m_OriginY = pInfo->m_OriginX; |
| 43 pInfo->m_OriginX = 0; | 43 pInfo->m_OriginX = 0; |
| 44 short vx, vy; | 44 short vx, vy; |
| 45 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); | 45 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); |
| 46 FX_FLOAT fontsize = m_TextState.GetFontSize(); | 46 FX_FLOAT fontsize = m_TextState.GetFontSize(); |
| 47 pInfo->m_OriginX -= fontsize * vx / 1000; | 47 pInfo->m_OriginX -= fontsize * vx / 1000; |
| 48 pInfo->m_OriginY -= fontsize * vy / 1000; | 48 pInfo->m_OriginY -= fontsize * vy / 1000; |
| 49 } | 49 } |
| 50 | 50 |
| 51 int CPDF_TextObject::CountChars() const { | 51 int CPDF_TextObject::CountChars() const { |
| 52 if (m_nChars == 1) { | 52 if (m_nChars == 1) { |
| 53 return 1; | 53 return 1; |
| 54 } | 54 } |
| 55 int count = 0; | 55 int count = 0; |
| 56 for (int i = 0; i < m_nChars; ++i) | 56 for (int i = 0; i < m_nChars; ++i) |
| 57 if (m_pCharCodes[i] != (FX_DWORD)-1) { | 57 if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) { |
| 58 ++count; | 58 ++count; |
| 59 } | 59 } |
| 60 return count; | 60 return count; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void CPDF_TextObject::GetCharInfo(int index, | 63 void CPDF_TextObject::GetCharInfo(int index, |
| 64 FX_DWORD& charcode, | 64 FX_DWORD& charcode, |
| 65 FX_FLOAT& kerning) const { | 65 FX_FLOAT& kerning) const { |
| 66 if (m_nChars == 1) { | 66 if (m_nChars == 1) { |
| 67 charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; | 67 charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; |
| 68 kerning = 0; | 68 kerning = 0; |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 int count = 0; | 71 int count = 0; |
| 72 for (int i = 0; i < m_nChars; ++i) { | 72 for (int i = 0; i < m_nChars; ++i) { |
| 73 if (m_pCharCodes[i] != (FX_DWORD)-1) { | 73 if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) { |
| 74 if (count == index) { | 74 if (count == index) { |
| 75 charcode = m_pCharCodes[i]; | 75 charcode = m_pCharCodes[i]; |
| 76 if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) { | 76 if (i == m_nChars - 1 || |
| 77 m_pCharCodes[i + 1] != CPDF_Font::kInvalidCharCode) { |
| 77 kerning = 0; | 78 kerning = 0; |
| 78 } else { | 79 } else { |
| 79 kerning = m_pCharPos[i]; | 80 kerning = m_pCharPos[i]; |
| 80 } | 81 } |
| 81 return; | 82 return; |
| 82 } | 83 } |
| 83 ++count; | 84 ++count; |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { | 89 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { |
| 89 if (m_nChars == 1) { | 90 if (m_nChars == 1) { |
| 90 GetItemInfo(0, pInfo); | 91 GetItemInfo(0, pInfo); |
| 91 return; | 92 return; |
| 92 } | 93 } |
| 93 int count = 0; | 94 int count = 0; |
| 94 for (int i = 0; i < m_nChars; ++i) { | 95 for (int i = 0; i < m_nChars; ++i) { |
| 95 FX_DWORD charcode = m_pCharCodes[i]; | 96 FX_DWORD charcode = m_pCharCodes[i]; |
| 96 if (charcode == (FX_DWORD)-1) { | 97 if (charcode == CPDF_Font::kInvalidCharCode) { |
| 97 continue; | 98 continue; |
| 98 } | 99 } |
| 99 if (count == index) { | 100 if (count == index) { |
| 100 GetItemInfo(i, pInfo); | 101 GetItemInfo(i, pInfo); |
| 101 break; | 102 break; |
| 102 } | 103 } |
| 103 ++count; | 104 ++count; |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); | 150 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); |
| 150 int index = 0; | 151 int index = 0; |
| 151 for (int i = 0; i < nsegs; ++i) { | 152 for (int i = 0; i < nsegs; ++i) { |
| 152 const FX_CHAR* segment = pStrs[i]; | 153 const FX_CHAR* segment = pStrs[i]; |
| 153 int offset = 0, len = pStrs[i].GetLength(); | 154 int offset = 0, len = pStrs[i].GetLength(); |
| 154 while (offset < len) { | 155 while (offset < len) { |
| 155 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); | 156 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); |
| 156 } | 157 } |
| 157 if (i != nsegs - 1) { | 158 if (i != nsegs - 1) { |
| 158 m_pCharPos[index - 1] = pKerning[i]; | 159 m_pCharPos[index - 1] = pKerning[i]; |
| 159 m_pCharCodes[index++] = (FX_DWORD)-1; | 160 m_pCharCodes[index++] = CPDF_Font::kInvalidCharCode; |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 } else { | 163 } else { |
| 163 int offset = 0; | 164 int offset = 0; |
| 164 m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( | 165 m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( |
| 165 pStrs[0], pStrs[0].GetLength(), offset); | 166 pStrs[0], pStrs[0].GetLength(), offset); |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 | 169 |
| 169 void CPDF_TextObject::SetText(const CFX_ByteString& str) { | 170 void CPDF_TextObject::SetText(const CFX_ByteString& str) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 199 FX_BOOL bVertWriting = FALSE; | 200 FX_BOOL bVertWriting = FALSE; |
| 200 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | 201 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); |
| 201 if (pCIDFont) { | 202 if (pCIDFont) { |
| 202 bVertWriting = pCIDFont->IsVertWriting(); | 203 bVertWriting = pCIDFont->IsVertWriting(); |
| 203 } | 204 } |
| 204 FX_FLOAT fontsize = m_TextState.GetFontSize(); | 205 FX_FLOAT fontsize = m_TextState.GetFontSize(); |
| 205 for (int i = 0; i < m_nChars; ++i) { | 206 for (int i = 0; i < m_nChars; ++i) { |
| 206 FX_DWORD charcode = | 207 FX_DWORD charcode = |
| 207 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; | 208 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; |
| 208 if (i > 0) { | 209 if (i > 0) { |
| 209 if (charcode == (FX_DWORD)-1) { | 210 if (charcode == CPDF_Font::kInvalidCharCode) { |
| 210 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; | 211 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; |
| 211 continue; | 212 continue; |
| 212 } | 213 } |
| 213 m_pCharPos[i - 1] = curpos; | 214 m_pCharPos[i - 1] = curpos; |
| 214 } | 215 } |
| 215 FX_RECT char_rect = pFont->GetCharBBox(charcode, level); | 216 FX_RECT char_rect = pFont->GetCharBBox(charcode, level); |
| 216 FX_FLOAT charwidth; | 217 FX_FLOAT charwidth; |
| 217 if (!bVertWriting) { | 218 if (!bVertWriting) { |
| 218 if (min_y > char_rect.top) { | 219 if (min_y > char_rect.top) { |
| 219 min_y = (FX_FLOAT)char_rect.top; | 220 min_y = (FX_FLOAT)char_rect.top; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { | 340 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { |
| 340 FX_FLOAT dx = x - m_PosX; | 341 FX_FLOAT dx = x - m_PosX; |
| 341 FX_FLOAT dy = y - m_PosY; | 342 FX_FLOAT dy = y - m_PosY; |
| 342 m_PosX = x; | 343 m_PosX = x; |
| 343 m_PosY = y; | 344 m_PosY = y; |
| 344 m_Left += dx; | 345 m_Left += dx; |
| 345 m_Right += dx; | 346 m_Right += dx; |
| 346 m_Top += dy; | 347 m_Top += dy; |
| 347 m_Bottom += dy; | 348 m_Bottom += dy; |
| 348 } | 349 } |
| OLD | NEW |