| 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/page/cpdf_textobject.h" | 7 #include "core/fpdfapi/page/cpdf_textobject.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/font/cpdf_cidfont.h" | 9 #include "core/fpdfapi/font/cpdf_cidfont.h" |
| 10 #include "core/fpdfapi/font/cpdf_font.h" | 10 #include "core/fpdfapi/font/cpdf_font.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 void CPDF_TextObject::SetText(const CFX_ByteString& str) { | 206 void CPDF_TextObject::SetText(const CFX_ByteString& str) { |
| 207 SetSegments(&str, nullptr, 1); | 207 SetSegments(&str, nullptr, 1); |
| 208 RecalcPositionData(); | 208 RecalcPositionData(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const { | 211 FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const { |
| 212 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; | 212 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; |
| 213 CPDF_Font* pFont = m_TextState.GetFont(); | 213 CPDF_Font* pFont = m_TextState.GetFont(); |
| 214 FX_BOOL bVertWriting = FALSE; | 214 bool bVertWriting = false; |
| 215 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | 215 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); |
| 216 if (pCIDFont) { | 216 if (pCIDFont) { |
| 217 bVertWriting = pCIDFont->IsVertWriting(); | 217 bVertWriting = pCIDFont->IsVertWriting(); |
| 218 } | 218 } |
| 219 if (!bVertWriting) | 219 if (!bVertWriting) |
| 220 return pFont->GetCharWidthF(charcode) * fontsize; | 220 return pFont->GetCharWidthF(charcode) * fontsize; |
| 221 | 221 |
| 222 uint16_t CID = pCIDFont->CIDFromCharCode(charcode); | 222 uint16_t CID = pCIDFont->CIDFromCharCode(charcode); |
| 223 return pCIDFont->GetVertWidth(CID) * fontsize; | 223 return pCIDFont->GetVertWidth(CID) * fontsize; |
| 224 } | 224 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 241 | 241 |
| 242 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, | 242 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, |
| 243 FX_FLOAT* pTextAdvanceY, | 243 FX_FLOAT* pTextAdvanceY, |
| 244 FX_FLOAT horz_scale) { | 244 FX_FLOAT horz_scale) { |
| 245 FX_FLOAT curpos = 0; | 245 FX_FLOAT curpos = 0; |
| 246 FX_FLOAT min_x = 10000 * 1.0f; | 246 FX_FLOAT min_x = 10000 * 1.0f; |
| 247 FX_FLOAT max_x = -10000 * 1.0f; | 247 FX_FLOAT max_x = -10000 * 1.0f; |
| 248 FX_FLOAT min_y = 10000 * 1.0f; | 248 FX_FLOAT min_y = 10000 * 1.0f; |
| 249 FX_FLOAT max_y = -10000 * 1.0f; | 249 FX_FLOAT max_y = -10000 * 1.0f; |
| 250 CPDF_Font* pFont = m_TextState.GetFont(); | 250 CPDF_Font* pFont = m_TextState.GetFont(); |
| 251 FX_BOOL bVertWriting = FALSE; | 251 bool bVertWriting = false; |
| 252 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | 252 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); |
| 253 if (pCIDFont) { | 253 if (pCIDFont) { |
| 254 bVertWriting = pCIDFont->IsVertWriting(); | 254 bVertWriting = pCIDFont->IsVertWriting(); |
| 255 } | 255 } |
| 256 FX_FLOAT fontsize = m_TextState.GetFontSize(); | 256 FX_FLOAT fontsize = m_TextState.GetFontSize(); |
| 257 for (int i = 0; i < m_nChars; ++i) { | 257 for (int i = 0; i < m_nChars; ++i) { |
| 258 uint32_t charcode = | 258 uint32_t charcode = |
| 259 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; | 259 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; |
| 260 if (i > 0) { | 260 if (i > 0) { |
| 261 if (charcode == CPDF_Font::kInvalidCharCode) { | 261 if (charcode == CPDF_Font::kInvalidCharCode) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 m_PosY = y; | 379 m_PosY = y; |
| 380 m_Left += dx; | 380 m_Left += dx; |
| 381 m_Right += dx; | 381 m_Right += dx; |
| 382 m_Top += dy; | 382 m_Top += dy; |
| 383 m_Bottom += dy; | 383 m_Bottom += dy; |
| 384 } | 384 } |
| 385 | 385 |
| 386 void CPDF_TextObject::RecalcPositionData() { | 386 void CPDF_TextObject::RecalcPositionData() { |
| 387 CalcPositionData(nullptr, nullptr, 1); | 387 CalcPositionData(nullptr, nullptr, 1); |
| 388 } | 388 } |
| OLD | NEW |