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 "fpdfsdk/pdfwindow/PWL_Utils.h" | 7 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fpdfdoc/include/cpvt_word.h" | 11 #include "core/fpdfdoc/include/cpvt_word.h" |
12 #include "core/fxge/include/fx_ge.h" | 12 #include "core/fxge/include/fx_ge.h" |
13 #include "fpdfsdk/fxedit/include/fx_edit.h" | 13 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
14 #include "fpdfsdk/pdfwindow/PWL_Icon.h" | 14 #include "fpdfsdk/pdfwindow/PWL_Icon.h" |
15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | 15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
16 | 16 |
17 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | 17 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
18 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | 18 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
19 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | 19 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
20 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) | 20 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
21 | 21 |
22 CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, | 22 CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, |
23 int32_t nCount) { | 23 int32_t nCount) { |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 FX_FLOAT fCenterX = (rect.left + rect.right) / 2.0f; | 406 FX_FLOAT fCenterX = (rect.left + rect.right) / 2.0f; |
407 FX_FLOAT fCenterY = (rect.top + rect.bottom) / 2.0f; | 407 FX_FLOAT fCenterY = (rect.top + rect.bottom) / 2.0f; |
408 | 408 |
409 FX_FLOAT fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; | 409 FX_FLOAT fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; |
410 | 410 |
411 return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius, | 411 return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius, |
412 fCenterX + fRadius, fCenterY + fRadius); | 412 fCenterX + fRadius, fCenterY + fRadius); |
413 } | 413 } |
414 | 414 |
415 CFX_ByteString CPWL_Utils::GetEditAppStream(IFX_Edit* pEdit, | 415 CFX_ByteString CPWL_Utils::GetEditAppStream(CFX_Edit* pEdit, |
416 const CFX_FloatPoint& ptOffset, | 416 const CFX_FloatPoint& ptOffset, |
417 const CPVT_WordRange* pRange, | 417 const CPVT_WordRange* pRange, |
418 FX_BOOL bContinuous, | 418 FX_BOOL bContinuous, |
419 uint16_t SubWord) { | 419 uint16_t SubWord) { |
420 return IFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous, | 420 return CFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous, |
421 SubWord); | 421 SubWord); |
422 } | 422 } |
423 | 423 |
424 CFX_ByteString CPWL_Utils::GetEditSelAppStream(IFX_Edit* pEdit, | 424 CFX_ByteString CPWL_Utils::GetEditSelAppStream(CFX_Edit* pEdit, |
425 const CFX_FloatPoint& ptOffset, | 425 const CFX_FloatPoint& ptOffset, |
426 const CPVT_WordRange* pRange) { | 426 const CPVT_WordRange* pRange) { |
427 return IFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange); | 427 return CFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange); |
428 } | 428 } |
429 | 429 |
430 CFX_ByteString CPWL_Utils::GetTextAppStream(const CFX_FloatRect& rcBBox, | 430 CFX_ByteString CPWL_Utils::GetTextAppStream(const CFX_FloatRect& rcBBox, |
431 IPVT_FontMap* pFontMap, | 431 IPVT_FontMap* pFontMap, |
432 const CFX_WideString& sText, | 432 const CFX_WideString& sText, |
433 int32_t nAlignmentH, | 433 int32_t nAlignmentH, |
434 int32_t nAlignmentV, | 434 int32_t nAlignmentV, |
435 FX_FLOAT fFontSize, | 435 FX_FLOAT fFontSize, |
436 FX_BOOL bMultiLine, | 436 FX_BOOL bMultiLine, |
437 FX_BOOL bAutoReturn, | 437 FX_BOOL bAutoReturn, |
438 const CPWL_Color& crText) { | 438 const CPWL_Color& crText) { |
439 CFX_ByteTextBuf sRet; | 439 CFX_ByteTextBuf sRet; |
440 | 440 |
441 IFX_Edit* pEdit = IFX_Edit::NewEdit(); | 441 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
442 pEdit->SetFontMap(pFontMap); | 442 pEdit->SetFontMap(pFontMap); |
443 pEdit->SetPlateRect(rcBBox); | 443 pEdit->SetPlateRect(rcBBox); |
444 pEdit->SetAlignmentH(nAlignmentH); | 444 pEdit->SetAlignmentH(nAlignmentH); |
445 pEdit->SetAlignmentV(nAlignmentV); | 445 pEdit->SetAlignmentV(nAlignmentV); |
446 pEdit->SetMultiLine(bMultiLine); | 446 pEdit->SetMultiLine(bMultiLine); |
447 pEdit->SetAutoReturn(bAutoReturn); | 447 pEdit->SetAutoReturn(bAutoReturn); |
448 if (IsFloatZero(fFontSize)) | 448 if (IsFloatZero(fFontSize)) |
449 pEdit->SetAutoFontSize(TRUE); | 449 pEdit->SetAutoFontSize(TRUE); |
450 else | 450 else |
451 pEdit->SetFontSize(fFontSize); | 451 pEdit->SetFontSize(fFontSize); |
452 | 452 |
453 pEdit->Initialize(); | 453 pEdit->Initialize(); |
454 pEdit->SetText(sText.c_str()); | 454 pEdit->SetText(sText.c_str()); |
455 | 455 |
456 CFX_ByteString sEdit = | 456 CFX_ByteString sEdit = |
457 CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); | 457 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); |
458 if (sEdit.GetLength() > 0) | 458 if (sEdit.GetLength() > 0) |
459 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; | 459 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; |
460 IFX_Edit::DelEdit(pEdit); | |
461 | 460 |
462 return sRet.MakeString(); | 461 return sRet.MakeString(); |
463 } | 462 } |
464 | 463 |
465 CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, | 464 CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, |
466 IPVT_FontMap* pFontMap, | 465 IPVT_FontMap* pFontMap, |
467 CPDF_Stream* pIconStream, | 466 CPDF_Stream* pIconStream, |
468 CPDF_IconFit& IconFit, | 467 CPDF_IconFit& IconFit, |
469 const CFX_WideString& sLabel, | 468 const CFX_WideString& sLabel, |
470 const CPWL_Color& crText, | 469 const CPWL_Color& crText, |
471 FX_FLOAT fFontSize, | 470 FX_FLOAT fFontSize, |
472 int32_t nLayOut) { | 471 int32_t nLayOut) { |
473 const FX_FLOAT fAutoFontScale = 1.0f / 3.0f; | 472 const FX_FLOAT fAutoFontScale = 1.0f / 3.0f; |
474 | 473 |
475 IFX_Edit* pEdit = IFX_Edit::NewEdit(); | 474 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
476 pEdit->SetFontMap(pFontMap); | 475 pEdit->SetFontMap(pFontMap); |
477 pEdit->SetAlignmentH(1); | 476 pEdit->SetAlignmentH(1); |
478 pEdit->SetAlignmentV(1); | 477 pEdit->SetAlignmentV(1); |
479 pEdit->SetMultiLine(FALSE); | 478 pEdit->SetMultiLine(FALSE); |
480 pEdit->SetAutoReturn(FALSE); | 479 pEdit->SetAutoReturn(FALSE); |
481 if (IsFloatZero(fFontSize)) | 480 if (IsFloatZero(fFontSize)) |
482 pEdit->SetAutoFontSize(TRUE); | 481 pEdit->SetAutoFontSize(TRUE); |
483 else | 482 else |
484 pEdit->SetFontSize(fFontSize); | 483 pEdit->SetFontSize(fFontSize); |
485 | 484 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 if (!rcIcon.IsEmpty()) { | 659 if (!rcIcon.IsEmpty()) { |
661 Icon.Move(rcIcon, FALSE, FALSE); | 660 Icon.Move(rcIcon, FALSE, FALSE); |
662 sTemp << Icon.GetImageAppStream(); | 661 sTemp << Icon.GetImageAppStream(); |
663 } | 662 } |
664 | 663 |
665 Icon.Destroy(); | 664 Icon.Destroy(); |
666 | 665 |
667 if (!rcLabel.IsEmpty()) { | 666 if (!rcLabel.IsEmpty()) { |
668 pEdit->SetPlateRect(rcLabel); | 667 pEdit->SetPlateRect(rcLabel); |
669 CFX_ByteString sEdit = | 668 CFX_ByteString sEdit = |
670 CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); | 669 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); |
671 if (sEdit.GetLength() > 0) { | 670 if (sEdit.GetLength() > 0) { |
672 sTemp << "BT\n" | 671 sTemp << "BT\n" |
673 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; | 672 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; |
674 } | 673 } |
675 } | 674 } |
676 | 675 |
677 IFX_Edit::DelEdit(pEdit); | |
678 if (sTemp.GetSize() > 0) { | 676 if (sTemp.GetSize() > 0) { |
679 sAppStream << "q\n" | 677 sAppStream << "q\n" |
680 << rcBBox.left << " " << rcBBox.bottom << " " | 678 << rcBBox.left << " " << rcBBox.bottom << " " |
681 << rcBBox.right - rcBBox.left << " " | 679 << rcBBox.right - rcBBox.left << " " |
682 << rcBBox.top - rcBBox.bottom << " re W n\n"; | 680 << rcBBox.top - rcBBox.bottom << " re W n\n"; |
683 sAppStream << sTemp << "Q\n"; | 681 sAppStream << sTemp << "Q\n"; |
684 } | 682 } |
685 return sAppStream.MakeString(); | 683 return sAppStream.MakeString(); |
686 } | 684 } |
687 | 685 |
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3347 break; | 3345 break; |
3348 case COLORTYPE_RGB: | 3346 case COLORTYPE_RGB: |
3349 CPWL_Utils::ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4, | 3347 CPWL_Utils::ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4, |
3350 fColor1, fColor2, fColor3); | 3348 fColor1, fColor2, fColor3); |
3351 break; | 3349 break; |
3352 } | 3350 } |
3353 break; | 3351 break; |
3354 } | 3352 } |
3355 nColorType = other_nColorType; | 3353 nColorType = other_nColorType; |
3356 } | 3354 } |
OLD | NEW |