| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "pageint.h" | 9 #include "pageint.h" |
| 10 CPDF_PageObject* CPDF_PageObject::Create(int type) { | 10 CPDF_PageObject* CPDF_PageObject::Create(int type) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 CPDF_TextObject::CPDF_TextObject() | 88 CPDF_TextObject::CPDF_TextObject() |
| 89 : m_PosX(0), | 89 : m_PosX(0), |
| 90 m_PosY(0), | 90 m_PosY(0), |
| 91 m_nChars(0), | 91 m_nChars(0), |
| 92 m_pCharCodes(nullptr), | 92 m_pCharCodes(nullptr), |
| 93 m_pCharPos(nullptr) { | 93 m_pCharPos(nullptr) { |
| 94 m_Type = PDFPAGE_TEXT; | 94 m_Type = PDFPAGE_TEXT; |
| 95 } | 95 } |
| 96 | 96 |
| 97 CPDF_TextObject::~CPDF_TextObject() { | 97 CPDF_TextObject::~CPDF_TextObject() { |
| 98 if (m_nChars > 1 && m_pCharCodes) { | 98 if (m_nChars > 1) { |
| 99 FX_Free(m_pCharCodes); | 99 FX_Free(m_pCharCodes); |
| 100 } | 100 } |
| 101 if (m_pCharPos) { | 101 FX_Free(m_pCharPos); |
| 102 FX_Free(m_pCharPos); | |
| 103 } | |
| 104 } | 102 } |
| 105 | 103 |
| 106 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { | 104 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { |
| 107 pInfo->m_CharCode = | 105 pInfo->m_CharCode = |
| 108 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; | 106 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; |
| 109 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; | 107 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; |
| 110 pInfo->m_OriginY = 0; | 108 pInfo->m_OriginY = 0; |
| 111 if (pInfo->m_CharCode == -1) { | 109 if (pInfo->m_CharCode == -1) { |
| 112 return; | 110 return; |
| 113 } | 111 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (count == index) { | 177 if (count == index) { |
| 180 GetItemInfo(i, pInfo); | 178 GetItemInfo(i, pInfo); |
| 181 break; | 179 break; |
| 182 } | 180 } |
| 183 ++count; | 181 ++count; |
| 184 } | 182 } |
| 185 } | 183 } |
| 186 | 184 |
| 187 void CPDF_TextObject::CopyData(const CPDF_PageObject* pSrc) { | 185 void CPDF_TextObject::CopyData(const CPDF_PageObject* pSrc) { |
| 188 const CPDF_TextObject* pSrcObj = (const CPDF_TextObject*)pSrc; | 186 const CPDF_TextObject* pSrcObj = (const CPDF_TextObject*)pSrc; |
| 189 if (m_nChars > 1 && m_pCharCodes) { | 187 if (m_nChars > 1) { |
| 190 FX_Free(m_pCharCodes); | 188 FX_Free(m_pCharCodes); |
| 191 m_pCharCodes = nullptr; | 189 m_pCharCodes = nullptr; |
| 192 } | 190 } |
| 193 if (m_pCharPos) { | 191 FX_Free(m_pCharPos); |
| 194 FX_Free(m_pCharPos); | 192 m_pCharPos = nullptr; |
| 195 m_pCharPos = nullptr; | |
| 196 } | |
| 197 m_nChars = pSrcObj->m_nChars; | 193 m_nChars = pSrcObj->m_nChars; |
| 198 if (m_nChars > 1) { | 194 if (m_nChars > 1) { |
| 199 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); | 195 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); |
| 200 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); | 196 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); |
| 201 for (int i = 0; i < m_nChars; ++i) { | 197 for (int i = 0; i < m_nChars; ++i) { |
| 202 m_pCharCodes[i] = pSrcObj->m_pCharCodes[i]; | 198 m_pCharCodes[i] = pSrcObj->m_pCharCodes[i]; |
| 203 } | 199 } |
| 204 for (int i = 0; i < m_nChars - 1; ++i) { | 200 for (int i = 0; i < m_nChars - 1; ++i) { |
| 205 m_pCharPos[i] = pSrcObj->m_pCharPos[i]; | 201 m_pCharPos[i] = pSrcObj->m_pCharPos[i]; |
| 206 } | 202 } |
| 207 } else { | 203 } else { |
| 208 m_pCharCodes = pSrcObj->m_pCharCodes; | 204 m_pCharCodes = pSrcObj->m_pCharCodes; |
| 209 } | 205 } |
| 210 m_PosX = pSrcObj->m_PosX; | 206 m_PosX = pSrcObj->m_PosX; |
| 211 m_PosY = pSrcObj->m_PosY; | 207 m_PosY = pSrcObj->m_PosY; |
| 212 } | 208 } |
| 213 | 209 |
| 214 void CPDF_TextObject::GetTextMatrix(CFX_AffineMatrix* pMatrix) const { | 210 void CPDF_TextObject::GetTextMatrix(CFX_AffineMatrix* pMatrix) const { |
| 215 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); | 211 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); |
| 216 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], | 212 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], |
| 217 m_PosX, m_PosY); | 213 m_PosX, m_PosY); |
| 218 } | 214 } |
| 219 | 215 |
| 220 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, | 216 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, |
| 221 FX_FLOAT* pKerning, | 217 FX_FLOAT* pKerning, |
| 222 int nsegs) { | 218 int nsegs) { |
| 223 if (m_nChars > 1 && m_pCharCodes) { | 219 if (m_nChars > 1) { |
| 224 FX_Free(m_pCharCodes); | 220 FX_Free(m_pCharCodes); |
| 225 m_pCharCodes = nullptr; | 221 m_pCharCodes = nullptr; |
| 226 } | 222 } |
| 227 if (m_pCharPos) { | 223 FX_Free(m_pCharPos); |
| 228 FX_Free(m_pCharPos); | 224 m_pCharPos = nullptr; |
| 229 m_pCharPos = nullptr; | |
| 230 } | |
| 231 CPDF_Font* pFont = m_TextState.GetFont(); | 225 CPDF_Font* pFont = m_TextState.GetFont(); |
| 232 m_nChars = 0; | 226 m_nChars = 0; |
| 233 for (int i = 0; i < nsegs; ++i) { | 227 for (int i = 0; i < nsegs; ++i) { |
| 234 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); | 228 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); |
| 235 } | 229 } |
| 236 m_nChars += nsegs - 1; | 230 m_nChars += nsegs - 1; |
| 237 if (m_nChars > 1) { | 231 if (m_nChars > 1) { |
| 238 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); | 232 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); |
| 239 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); | 233 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); |
| 240 int index = 0; | 234 int index = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 255 pStrs[0], pStrs[0].GetLength(), offset); | 249 pStrs[0], pStrs[0].GetLength(), offset); |
| 256 } | 250 } |
| 257 } | 251 } |
| 258 | 252 |
| 259 void CPDF_TextObject::SetText(const CFX_ByteString& str) { | 253 void CPDF_TextObject::SetText(const CFX_ByteString& str) { |
| 260 SetSegments(&str, nullptr, 1); | 254 SetSegments(&str, nullptr, 1); |
| 261 RecalcPositionData(); | 255 RecalcPositionData(); |
| 262 } | 256 } |
| 263 | 257 |
| 264 void CPDF_TextObject::SetEmpty() { | 258 void CPDF_TextObject::SetEmpty() { |
| 265 if (m_nChars > 1 && m_pCharCodes) { | 259 if (m_nChars > 1) { |
| 266 FX_Free(m_pCharCodes); | 260 FX_Free(m_pCharCodes); |
| 267 } | 261 } |
| 268 if (m_nChars > 1 && m_pCharPos) { | 262 if (m_nChars > 1) { |
| 269 FX_Free(m_pCharPos); | 263 FX_Free(m_pCharPos); |
| 270 } | 264 } |
| 271 m_nChars = 0; | 265 m_nChars = 0; |
| 272 m_pCharCodes = nullptr; | 266 m_pCharCodes = nullptr; |
| 273 m_pCharPos = nullptr; | 267 m_pCharPos = nullptr; |
| 274 m_Left = m_Right = m_PosX; | 268 m_Left = m_Right = m_PosX; |
| 275 m_Top = m_Bottom = m_PosY; | 269 m_Top = m_Bottom = m_PosY; |
| 276 } | 270 } |
| 277 | 271 |
| 278 void CPDF_TextObject::SetText(CFX_ByteString* pStrs, | 272 void CPDF_TextObject::SetText(CFX_ByteString* pStrs, |
| 279 FX_FLOAT* pKerning, | 273 FX_FLOAT* pKerning, |
| 280 int nSegs) { | 274 int nSegs) { |
| 281 SetSegments(pStrs, pKerning, nSegs); | 275 SetSegments(pStrs, pKerning, nSegs); |
| 282 RecalcPositionData(); | 276 RecalcPositionData(); |
| 283 } | 277 } |
| 284 | 278 |
| 285 void CPDF_TextObject::SetText(int nChars, | 279 void CPDF_TextObject::SetText(int nChars, |
| 286 FX_DWORD* pCharCodes, | 280 FX_DWORD* pCharCodes, |
| 287 FX_FLOAT* pKernings) { | 281 FX_FLOAT* pKernings) { |
| 288 if (m_nChars > 1 && m_pCharCodes) { | 282 if (m_nChars > 1) { |
| 289 FX_Free(m_pCharCodes); | 283 FX_Free(m_pCharCodes); |
| 290 m_pCharCodes = nullptr; | 284 m_pCharCodes = nullptr; |
| 291 } | 285 } |
| 292 if (m_pCharPos) { | 286 FX_Free(m_pCharPos); |
| 293 FX_Free(m_pCharPos); | 287 m_pCharPos = nullptr; |
| 294 m_pCharPos = nullptr; | |
| 295 } | |
| 296 int nKernings = 0; | 288 int nKernings = 0; |
| 297 int i; | 289 int i; |
| 298 for (i = 0; i < nChars - 1; ++i) { | 290 for (i = 0; i < nChars - 1; ++i) { |
| 299 if (pKernings[i] != 0) { | 291 if (pKernings[i] != 0) { |
| 300 ++nKernings; | 292 ++nKernings; |
| 301 } | 293 } |
| 302 } | 294 } |
| 303 m_nChars = nChars + nKernings; | 295 m_nChars = nChars + nKernings; |
| 304 if (m_nChars > 1) { | 296 if (m_nChars > 1) { |
| 305 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); | 297 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 (FX_FLOAT)y0); | 1004 (FX_FLOAT)y0); |
| 1013 matrix = m_PageMatrix; | 1005 matrix = m_PageMatrix; |
| 1014 matrix.Concat(display_matrix); | 1006 matrix.Concat(display_matrix); |
| 1015 } | 1007 } |
| 1016 CPDF_ParseOptions::CPDF_ParseOptions() { | 1008 CPDF_ParseOptions::CPDF_ParseOptions() { |
| 1017 m_bTextOnly = FALSE; | 1009 m_bTextOnly = FALSE; |
| 1018 m_bMarkedContent = TRUE; | 1010 m_bMarkedContent = TRUE; |
| 1019 m_bSeparateForm = TRUE; | 1011 m_bSeparateForm = TRUE; |
| 1020 m_bDecodeInlineImage = FALSE; | 1012 m_bDecodeInlineImage = FALSE; |
| 1021 } | 1013 } |
| OLD | NEW |