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/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 : 0; | 208 : 0; |
209 CPVT_FontMap map( | 209 CPVT_FontMap map( |
210 pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, | 210 pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, |
211 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 211 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
212 CPDF_VariableText::Provider prd(&map); | 212 CPDF_VariableText::Provider prd(&map); |
213 CPDF_VariableText vt; | 213 CPDF_VariableText vt; |
214 vt.SetProvider(&prd); | 214 vt.SetProvider(&prd); |
215 vt.SetPlateRect(rcBody); | 215 vt.SetPlateRect(rcBody); |
216 vt.SetAlignment(nAlign); | 216 vt.SetAlignment(nAlign); |
217 if (IsFloatZero(fFontSize)) | 217 if (IsFloatZero(fFontSize)) |
218 vt.SetAutoFontSize(TRUE); | 218 vt.SetAutoFontSize(true); |
219 else | 219 else |
220 vt.SetFontSize(fFontSize); | 220 vt.SetFontSize(fFontSize); |
221 | 221 |
222 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; | 222 bool bMultiLine = (dwFlags >> 12) & 1; |
223 if (bMultiLine) { | 223 if (bMultiLine) { |
224 vt.SetMultiLine(TRUE); | 224 vt.SetMultiLine(true); |
225 vt.SetAutoReturn(TRUE); | 225 vt.SetAutoReturn(true); |
226 } | 226 } |
227 uint16_t subWord = 0; | 227 uint16_t subWord = 0; |
228 if ((dwFlags >> 13) & 1) { | 228 if ((dwFlags >> 13) & 1) { |
229 subWord = '*'; | 229 subWord = '*'; |
230 vt.SetPasswordChar(subWord); | 230 vt.SetPasswordChar(subWord); |
231 } | 231 } |
232 FX_BOOL bCharArray = (dwFlags >> 24) & 1; | 232 bool bCharArray = (dwFlags >> 24) & 1; |
233 if (bCharArray) | 233 if (bCharArray) |
234 vt.SetCharArray(dwMaxLen); | 234 vt.SetCharArray(dwMaxLen); |
235 else | 235 else |
236 vt.SetLimitChar(dwMaxLen); | 236 vt.SetLimitChar(dwMaxLen); |
237 | 237 |
238 vt.Initialize(); | 238 vt.Initialize(); |
239 vt.SetText(swValue); | 239 vt.SetText(swValue); |
240 vt.RearrangeAll(); | 240 vt.RearrangeAll(); |
241 CFX_FloatRect rcContent = vt.GetContentRect(); | 241 CFX_FloatRect rcContent = vt.GetContentRect(); |
242 CFX_FloatPoint ptOffset; | 242 CFX_FloatPoint ptOffset; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 CPDF_VariableText vt; | 274 CPDF_VariableText vt; |
275 vt.SetProvider(&prd); | 275 vt.SetProvider(&prd); |
276 CFX_FloatRect rcButton = rcBody; | 276 CFX_FloatRect rcButton = rcBody; |
277 rcButton.left = rcButton.right - 13; | 277 rcButton.left = rcButton.right - 13; |
278 rcButton.Normalize(); | 278 rcButton.Normalize(); |
279 CFX_FloatRect rcEdit = rcBody; | 279 CFX_FloatRect rcEdit = rcBody; |
280 rcEdit.right = rcButton.left; | 280 rcEdit.right = rcButton.left; |
281 rcEdit.Normalize(); | 281 rcEdit.Normalize(); |
282 vt.SetPlateRect(rcEdit); | 282 vt.SetPlateRect(rcEdit); |
283 if (IsFloatZero(fFontSize)) | 283 if (IsFloatZero(fFontSize)) |
284 vt.SetAutoFontSize(TRUE); | 284 vt.SetAutoFontSize(true); |
285 else | 285 else |
286 vt.SetFontSize(fFontSize); | 286 vt.SetFontSize(fFontSize); |
287 | 287 |
288 vt.Initialize(); | 288 vt.Initialize(); |
289 vt.SetText(swValue); | 289 vt.SetText(swValue); |
290 vt.RearrangeAll(); | 290 vt.RearrangeAll(); |
291 CFX_FloatRect rcContent = vt.GetContentRect(); | 291 CFX_FloatRect rcContent = vt.GetContentRect(); |
292 CFX_FloatPoint ptOffset = | 292 CFX_FloatPoint ptOffset = |
293 CFX_FloatPoint(0.0f, (rcContent.Height() - rcEdit.Height()) / 2.0f); | 293 CFX_FloatPoint(0.0f, (rcContent.Height() - rcEdit.Height()) / 2.0f); |
294 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP( | 294 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP( |
295 &map, vt.GetIterator(), ptOffset, TRUE, 0); | 295 &map, vt.GetIterator(), ptOffset, true, 0); |
296 if (sEdit.GetLength() > 0) { | 296 if (sEdit.GetLength() > 0) { |
297 sAppStream << "/Tx BMC\n" | 297 sAppStream << "/Tx BMC\n" |
298 << "q\n"; | 298 << "q\n"; |
299 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " | 299 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " |
300 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; | 300 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; |
301 sAppStream << "BT\n" | 301 sAppStream << "BT\n" |
302 << CPVT_GenerateAP::GenerateColorAP(crText, | 302 << CPVT_GenerateAP::GenerateColorAP(crText, |
303 PaintOperation::FILL) | 303 PaintOperation::FILL) |
304 << sEdit << "ET\n" | 304 << sEdit << "ET\n" |
305 << "Q\nEMC\n"; | 305 << "Q\nEMC\n"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (IsFloatSmaller(fy, rcBody.bottom)) | 352 if (IsFloatSmaller(fy, rcBody.bottom)) |
353 break; | 353 break; |
354 | 354 |
355 if (CPDF_Object* pOpt = pOpts->GetDirectObjectAt(i)) { | 355 if (CPDF_Object* pOpt = pOpts->GetDirectObjectAt(i)) { |
356 CFX_WideString swItem; | 356 CFX_WideString swItem; |
357 if (pOpt->IsString()) | 357 if (pOpt->IsString()) |
358 swItem = pOpt->GetUnicodeText(); | 358 swItem = pOpt->GetUnicodeText(); |
359 else if (CPDF_Array* pArray = pOpt->AsArray()) | 359 else if (CPDF_Array* pArray = pOpt->AsArray()) |
360 swItem = pArray->GetDirectObjectAt(1)->GetUnicodeText(); | 360 swItem = pArray->GetDirectObjectAt(1)->GetUnicodeText(); |
361 | 361 |
362 FX_BOOL bSelected = FALSE; | 362 bool bSelected = false; |
363 if (pSels) { | 363 if (pSels) { |
364 for (size_t s = 0, ssz = pSels->GetCount(); s < ssz; s++) { | 364 for (size_t s = 0, ssz = pSels->GetCount(); s < ssz; s++) { |
365 int value = pSels->GetIntegerAt(s); | 365 int value = pSels->GetIntegerAt(s); |
366 if (value >= 0 && i == static_cast<size_t>(value)) { | 366 if (value >= 0 && i == static_cast<size_t>(value)) { |
367 bSelected = TRUE; | 367 bSelected = true; |
368 break; | 368 break; |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 CPDF_VariableText vt; | 372 CPDF_VariableText vt; |
373 vt.SetProvider(&prd); | 373 vt.SetProvider(&prd); |
374 vt.SetPlateRect( | 374 vt.SetPlateRect( |
375 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); | 375 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); |
376 vt.SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); | 376 vt.SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
377 | 377 |
(...skipping 11 matching lines...) Expand all Loading... |
389 PaintOperation::FILL) | 389 PaintOperation::FILL) |
390 << rcItem.left << " " << rcItem.bottom << " " | 390 << rcItem.left << " " << rcItem.bottom << " " |
391 << rcItem.Width() << " " << rcItem.Height() << " re f\n" | 391 << rcItem.Width() << " " << rcItem.Height() << " re f\n" |
392 << "Q\n"; | 392 << "Q\n"; |
393 sBody << "BT\n" | 393 sBody << "BT\n" |
394 << CPVT_GenerateAP::GenerateColorAP( | 394 << CPVT_GenerateAP::GenerateColorAP( |
395 CPVT_Color(CPVT_Color::kGray, 1), | 395 CPVT_Color(CPVT_Color::kGray, 1), |
396 PaintOperation::FILL) | 396 PaintOperation::FILL) |
397 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), | 397 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
398 CFX_FloatPoint(0.0f, fy), | 398 CFX_FloatPoint(0.0f, fy), |
399 TRUE, 0) | 399 true, 0) |
400 << "ET\n"; | 400 << "ET\n"; |
401 } else { | 401 } else { |
402 sBody << "BT\n" | 402 sBody << "BT\n" |
403 << CPVT_GenerateAP::GenerateColorAP(crText, | 403 << CPVT_GenerateAP::GenerateColorAP(crText, |
404 PaintOperation::FILL) | 404 PaintOperation::FILL) |
405 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), | 405 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
406 CFX_FloatPoint(0.0f, fy), | 406 CFX_FloatPoint(0.0f, fy), |
407 TRUE, 0) | 407 true, 0) |
408 << "ET\n"; | 408 << "ET\n"; |
409 } | 409 } |
410 fy -= fItemHeight; | 410 fy -= fItemHeight; |
411 } | 411 } |
412 } | 412 } |
413 } | 413 } |
414 if (sBody.GetSize() > 0) { | 414 if (sBody.GetSize() > 0) { |
415 sAppStream << "/Tx BMC\nq\n" | 415 sAppStream << "/Tx BMC\nq\n" |
416 << rcBody.left << " " << rcBody.bottom << " " | 416 << rcBody.left << " " << rcBody.bottom << " " |
417 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" | 417 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 CFX_WideString swValue(pAnnotDict.GetUnicodeTextFor("T")); | 508 CFX_WideString swValue(pAnnotDict.GetUnicodeTextFor("T")); |
509 swValue += L'\n'; | 509 swValue += L'\n'; |
510 swValue += pAnnotDict.GetUnicodeTextFor("Contents"); | 510 swValue += pAnnotDict.GetUnicodeTextFor("Contents"); |
511 CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName); | 511 CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName); |
512 | 512 |
513 CPDF_VariableText::Provider prd(&map); | 513 CPDF_VariableText::Provider prd(&map); |
514 CPDF_VariableText vt; | 514 CPDF_VariableText vt; |
515 vt.SetProvider(&prd); | 515 vt.SetProvider(&prd); |
516 vt.SetPlateRect(pAnnotDict.GetRectFor("Rect")); | 516 vt.SetPlateRect(pAnnotDict.GetRectFor("Rect")); |
517 vt.SetFontSize(12); | 517 vt.SetFontSize(12); |
518 vt.SetAutoReturn(TRUE); | 518 vt.SetAutoReturn(true); |
519 vt.SetMultiLine(TRUE); | 519 vt.SetMultiLine(true); |
520 | 520 |
521 vt.Initialize(); | 521 vt.Initialize(); |
522 vt.SetText(swValue); | 522 vt.SetText(swValue); |
523 vt.RearrangeAll(); | 523 vt.RearrangeAll(); |
524 CFX_FloatPoint ptOffset(3.0f, -3.0f); | 524 CFX_FloatPoint ptOffset(3.0f, -3.0f); |
525 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP( | 525 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP( |
526 &map, vt.GetIterator(), ptOffset, FALSE, 0); | 526 &map, vt.GetIterator(), ptOffset, false, 0); |
527 | 527 |
528 if (sContent.IsEmpty()) | 528 if (sContent.IsEmpty()) |
529 return CFX_ByteString(); | 529 return CFX_ByteString(); |
530 | 530 |
531 CFX_ByteTextBuf sAppStream; | 531 CFX_ByteTextBuf sAppStream; |
532 sAppStream << "BT\n" | 532 sAppStream << "BT\n" |
533 << CPVT_GenerateAP::GenerateColorAP( | 533 << CPVT_GenerateAP::GenerateColorAP( |
534 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) | 534 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) |
535 << sContent << "ET\n" | 535 << sContent << "ET\n" |
536 << "Q\n"; | 536 << "Q\n"; |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 1091 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
1092 true /*IsTextMarkupAnnotation*/); | 1092 true /*IsTextMarkupAnnotation*/); |
1093 return true; | 1093 return true; |
1094 } | 1094 } |
1095 | 1095 |
1096 // Static. | 1096 // Static. |
1097 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 1097 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
1098 IPVT_FontMap* pFontMap, | 1098 IPVT_FontMap* pFontMap, |
1099 CPDF_VariableText::Iterator* pIterator, | 1099 CPDF_VariableText::Iterator* pIterator, |
1100 const CFX_FloatPoint& ptOffset, | 1100 const CFX_FloatPoint& ptOffset, |
1101 FX_BOOL bContinuous, | 1101 bool bContinuous, |
1102 uint16_t SubWord) { | 1102 uint16_t SubWord) { |
1103 CFX_ByteTextBuf sEditStream; | 1103 CFX_ByteTextBuf sEditStream; |
1104 CFX_ByteTextBuf sLineStream; | 1104 CFX_ByteTextBuf sLineStream; |
1105 CFX_ByteTextBuf sWords; | 1105 CFX_ByteTextBuf sWords; |
1106 CFX_FloatPoint ptOld; | 1106 CFX_FloatPoint ptOld; |
1107 CFX_FloatPoint ptNew; | 1107 CFX_FloatPoint ptNew; |
1108 int32_t nCurFontIndex = -1; | 1108 int32_t nCurFontIndex = -1; |
1109 CPVT_WordPlace oldplace; | 1109 CPVT_WordPlace oldplace; |
1110 | 1110 |
1111 pIterator->SetAt(0); | 1111 pIterator->SetAt(0); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 int32_t nFontIndex, | 1353 int32_t nFontIndex, |
1354 FX_FLOAT fFontSize) { | 1354 FX_FLOAT fFontSize) { |
1355 CFX_ByteTextBuf sRet; | 1355 CFX_ByteTextBuf sRet; |
1356 if (pFontMap) { | 1356 if (pFontMap) { |
1357 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1357 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
1358 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1358 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
1359 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1359 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
1360 } | 1360 } |
1361 return sRet.MakeString(); | 1361 return sRet.MakeString(); |
1362 } | 1362 } |
OLD | NEW |