| 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/cpdf_textobject.h" | 7 #include "core/fpdfapi/fpdf_page/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/cpdf_font.h" | 10 #include "core/fpdfapi/fpdf_font/cpdf_font.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 FX_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, 0) * 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 } |
| 225 | 225 |
| 226 FX_FLOAT CPDF_TextObject::GetPosX() const { | 226 FX_FLOAT CPDF_TextObject::GetPosX() const { |
| 227 return m_PosX; | 227 return m_PosX; |
| 228 } | 228 } |
| 229 | 229 |
| 230 FX_FLOAT CPDF_TextObject::GetPosY() const { | 230 FX_FLOAT CPDF_TextObject::GetPosY() const { |
| 231 return m_PosY; | 231 return m_PosY; |
| 232 } | 232 } |
| 233 | 233 |
| 234 CPDF_Font* CPDF_TextObject::GetFont() const { | 234 CPDF_Font* CPDF_TextObject::GetFont() const { |
| 235 return m_TextState.GetFont(); | 235 return m_TextState.GetFont(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 FX_FLOAT CPDF_TextObject::GetFontSize() const { | 238 FX_FLOAT CPDF_TextObject::GetFontSize() const { |
| 239 return m_TextState.GetFontSize(); | 239 return m_TextState.GetFontSize(); |
| 240 } | 240 } |
| 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 int level) { | |
| 246 FX_FLOAT curpos = 0; | 245 FX_FLOAT curpos = 0; |
| 247 FX_FLOAT min_x = 10000 * 1.0f; | 246 FX_FLOAT min_x = 10000 * 1.0f; |
| 248 FX_FLOAT max_x = -10000 * 1.0f; | 247 FX_FLOAT max_x = -10000 * 1.0f; |
| 249 FX_FLOAT min_y = 10000 * 1.0f; | 248 FX_FLOAT min_y = 10000 * 1.0f; |
| 250 FX_FLOAT max_y = -10000 * 1.0f; | 249 FX_FLOAT max_y = -10000 * 1.0f; |
| 251 CPDF_Font* pFont = m_TextState.GetFont(); | 250 CPDF_Font* pFont = m_TextState.GetFont(); |
| 252 FX_BOOL bVertWriting = FALSE; | 251 FX_BOOL bVertWriting = FALSE; |
| 253 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | 252 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); |
| 254 if (pCIDFont) { | 253 if (pCIDFont) { |
| 255 bVertWriting = pCIDFont->IsVertWriting(); | 254 bVertWriting = pCIDFont->IsVertWriting(); |
| 256 } | 255 } |
| 257 FX_FLOAT fontsize = m_TextState.GetFontSize(); | 256 FX_FLOAT fontsize = m_TextState.GetFontSize(); |
| 258 for (int i = 0; i < m_nChars; ++i) { | 257 for (int i = 0; i < m_nChars; ++i) { |
| 259 uint32_t charcode = | 258 uint32_t charcode = |
| 260 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]; |
| 261 if (i > 0) { | 260 if (i > 0) { |
| 262 if (charcode == CPDF_Font::kInvalidCharCode) { | 261 if (charcode == CPDF_Font::kInvalidCharCode) { |
| 263 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; | 262 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; |
| 264 continue; | 263 continue; |
| 265 } | 264 } |
| 266 m_pCharPos[i - 1] = curpos; | 265 m_pCharPos[i - 1] = curpos; |
| 267 } | 266 } |
| 268 FX_RECT char_rect = pFont->GetCharBBox(charcode, level); | 267 FX_RECT char_rect = pFont->GetCharBBox(charcode); |
| 269 FX_FLOAT charwidth; | 268 FX_FLOAT charwidth; |
| 270 if (!bVertWriting) { | 269 if (!bVertWriting) { |
| 271 if (min_y > char_rect.top) { | 270 if (min_y > char_rect.top) { |
| 272 min_y = (FX_FLOAT)char_rect.top; | 271 min_y = (FX_FLOAT)char_rect.top; |
| 273 } | 272 } |
| 274 if (max_y < char_rect.top) { | 273 if (max_y < char_rect.top) { |
| 275 max_y = (FX_FLOAT)char_rect.top; | 274 max_y = (FX_FLOAT)char_rect.top; |
| 276 } | 275 } |
| 277 if (min_y > char_rect.bottom) { | 276 if (min_y > char_rect.bottom) { |
| 278 min_y = (FX_FLOAT)char_rect.bottom; | 277 min_y = (FX_FLOAT)char_rect.bottom; |
| 279 } | 278 } |
| 280 if (max_y < char_rect.bottom) { | 279 if (max_y < char_rect.bottom) { |
| 281 max_y = (FX_FLOAT)char_rect.bottom; | 280 max_y = (FX_FLOAT)char_rect.bottom; |
| 282 } | 281 } |
| 283 FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000; | 282 FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000; |
| 284 FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000; | 283 FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000; |
| 285 if (min_x > char_left) { | 284 if (min_x > char_left) { |
| 286 min_x = char_left; | 285 min_x = char_left; |
| 287 } | 286 } |
| 288 if (max_x < char_left) { | 287 if (max_x < char_left) { |
| 289 max_x = char_left; | 288 max_x = char_left; |
| 290 } | 289 } |
| 291 if (min_x > char_right) { | 290 if (min_x > char_right) { |
| 292 min_x = char_right; | 291 min_x = char_right; |
| 293 } | 292 } |
| 294 if (max_x < char_right) { | 293 if (max_x < char_right) { |
| 295 max_x = char_right; | 294 max_x = char_right; |
| 296 } | 295 } |
| 297 charwidth = pFont->GetCharWidthF(charcode, level) * fontsize / 1000; | 296 charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000; |
| 298 } else { | 297 } else { |
| 299 uint16_t CID = pCIDFont->CIDFromCharCode(charcode); | 298 uint16_t CID = pCIDFont->CIDFromCharCode(charcode); |
| 300 short vx; | 299 short vx; |
| 301 short vy; | 300 short vy; |
| 302 pCIDFont->GetVertOrigin(CID, vx, vy); | 301 pCIDFont->GetVertOrigin(CID, vx, vy); |
| 303 char_rect.left -= vx; | 302 char_rect.left -= vx; |
| 304 char_rect.right -= vx; | 303 char_rect.right -= vx; |
| 305 char_rect.top -= vy; | 304 char_rect.top -= vy; |
| 306 char_rect.bottom -= vy; | 305 char_rect.bottom -= vy; |
| 307 if (min_x > char_rect.left) { | 306 if (min_x > char_rect.left) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 m_PosY = y; | 379 m_PosY = y; |
| 381 m_Left += dx; | 380 m_Left += dx; |
| 382 m_Right += dx; | 381 m_Right += dx; |
| 383 m_Top += dy; | 382 m_Top += dy; |
| 384 m_Bottom += dy; | 383 m_Bottom += dy; |
| 385 } | 384 } |
| 386 | 385 |
| 387 void CPDF_TextObject::RecalcPositionData() { | 386 void CPDF_TextObject::RecalcPositionData() { |
| 388 CalcPositionData(nullptr, nullptr, 1); | 387 CalcPositionData(nullptr, nullptr, 1); |
| 389 } | 388 } |
| OLD | NEW |