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 "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 CFX_ByteTextBuf sDashStream; | 502 CFX_ByteTextBuf sDashStream; |
503 | 503 |
504 sDashStream << "["; | 504 sDashStream << "["; |
505 for (size_t i = 0; i < pDashArrayCount; ++i) | 505 for (size_t i = 0; i < pDashArrayCount; ++i) |
506 sDashStream << pDashArray->GetNumberAt(i) << " "; | 506 sDashStream << pDashArray->GetNumberAt(i) << " "; |
507 sDashStream << "] 0 d\n"; | 507 sDashStream << "] 0 d\n"; |
508 | 508 |
509 return sDashStream.MakeString(); | 509 return sDashStream.MakeString(); |
510 } | 510 } |
511 | 511 |
512 CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, | |
513 const CPDF_Dictionary& pAnnotDict, | |
514 CPDF_Font* pDefFont, | |
515 const CFX_ByteString& sFontName) { | |
516 CFX_WideString swValue(L"Author: "); | |
jaepark
2016/08/29 21:19:24
I've deleted this line because "T" field stands fo
| |
517 swValue += pAnnotDict.GetUnicodeTextBy("T"); | |
Lei Zhang
2016/08/27 02:16:53
Do you care if GetUnicodeTextBy() returns an empty
jaepark
2016/08/29 21:19:24
if GetUnicodeTextBy() returns empty string, we wil
| |
518 swValue += L'\n'; | |
519 swValue += pAnnotDict.GetUnicodeTextBy("Contents"); | |
Lei Zhang
2016/08/27 02:16:53
Similarly, if there's no content, do you still wan
jaepark
2016/08/29 21:19:24
If there is no content, PopupAnnot should not be c
| |
520 CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName); | |
521 | |
522 CPDF_VariableText vt; | |
523 CPDF_VariableText::Provider prd(&map); | |
524 vt.SetProvider(&prd); | |
Lei Zhang
2016/08/27 02:16:53
The objects are destroyed in the reverse order of
jaepark
2016/08/29 21:19:24
Done.
| |
525 CFX_FloatRect rect = pAnnotDict.GetRectBy("Rect"); | |
Lei Zhang
2016/08/27 02:16:53
Drop the variable and merge with the next line?
jaepark
2016/08/29 21:19:24
Done.
| |
526 vt.SetPlateRect(rect); | |
527 vt.SetFontSize(12); | |
528 vt.SetAutoReturn(TRUE); | |
529 vt.SetMultiLine(TRUE); | |
530 | |
531 vt.Initialize(); | |
532 vt.SetText(swValue.c_str()); | |
533 vt.RearrangeAll(); | |
534 CFX_FloatPoint ptOffset(3.0f, -3.0f); | |
535 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP( | |
536 &map, vt.GetIterator(), ptOffset, FALSE, 0); | |
537 | |
538 if (sContent.IsEmpty()) | |
539 return CFX_ByteString(); | |
540 | |
541 CFX_ByteTextBuf sAppStream; | |
542 sAppStream << "BT\n" | |
543 << CPVT_GenerateAP::GenerateColorAP( | |
544 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) | |
545 << sContent << "ET\n" | |
546 << "Q\n"; | |
547 return sAppStream.MakeString(); | |
548 } | |
549 | |
512 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, | 550 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, |
513 const CFX_ByteString& sExtGSDictName, | 551 const CFX_ByteString& sExtGSDictName, |
514 const CFX_ByteString& sBlendMode) { | 552 const CFX_ByteString& sBlendMode) { |
515 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; | 553 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; |
516 pGSDict->SetAtString("Type", "ExtGState"); | 554 pGSDict->SetAtString("Type", "ExtGState"); |
517 | 555 |
518 FX_FLOAT fOpacity = | 556 FX_FLOAT fOpacity = |
519 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1; | 557 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1; |
520 pGSDict->SetAtNumber("CA", fOpacity); | 558 pGSDict->SetAtNumber("CA", fOpacity); |
521 pGSDict->SetAtNumber("ca", fOpacity); | 559 pGSDict->SetAtNumber("ca", fOpacity); |
522 pGSDict->SetAtBoolean("AIS", false); | 560 pGSDict->SetAtBoolean("AIS", false); |
523 pGSDict->SetAtString("BM", sBlendMode); | 561 pGSDict->SetAtString("BM", sBlendMode); |
524 | 562 |
525 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; | 563 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; |
526 pExtGStateDict->SetAt(sExtGSDictName, pGSDict); | 564 pExtGStateDict->SetAt(sExtGSDictName, pGSDict); |
527 | 565 |
528 return pExtGStateDict; | 566 return pExtGStateDict; |
529 } | 567 } |
530 | 568 |
531 // Takes ownership of |pExtGStateDict|. | 569 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, |
570 const CFX_ByteString& sFontDictName) { | |
571 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; | |
572 pFontDict->SetAtName("Type", "Font"); | |
573 pFontDict->SetAtName("Subtype", "Type1"); | |
574 pFontDict->SetAtName("BaseFont", "Helvetica"); | |
575 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); | |
576 pDoc->AddIndirectObject(pFontDict); | |
577 | |
578 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary; | |
579 pResourceFontDict->SetAtReference(sFontDictName, pDoc, pFontDict); | |
580 | |
581 return pResourceFontDict; | |
582 } | |
583 | |
584 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. | |
585 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, | |
586 CPDF_Dictionary* pResourceFontDict) { | |
587 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | |
588 if (pExtGStateDict) | |
589 pResourceDict->SetAt("ExtGState", pExtGStateDict); | |
590 | |
591 if (pResourceFontDict) | |
592 pResourceDict->SetAt("Font", pResourceFontDict); | |
593 | |
594 return pResourceDict; | |
595 } | |
596 | |
597 // Takes ownership of |pResourceDict|. | |
532 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 598 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
533 CPDF_Dictionary* pAnnotDict, | 599 CPDF_Dictionary* pAnnotDict, |
534 const CFX_ByteTextBuf& sAppStream, | 600 const CFX_ByteTextBuf& sAppStream, |
535 CPDF_Dictionary* pExtGStateDict) { | 601 CPDF_Dictionary* pResourceDict) { |
536 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; | 602 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; |
537 pAnnotDict->SetAt("AP", pAPDict); | 603 pAnnotDict->SetAt("AP", pAPDict); |
538 | 604 |
539 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 605 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
540 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 606 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
541 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); | 607 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); |
542 | 608 |
543 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, | 609 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, |
544 FALSE); | 610 FALSE); |
545 | 611 |
546 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 612 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
547 pStreamDict->SetAtInteger("FormType", 1); | 613 pStreamDict->SetAtInteger("FormType", 1); |
548 pStreamDict->SetAtString("Subtype", "Form"); | 614 pStreamDict->SetAtString("Subtype", "Form"); |
549 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); | 615 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
550 | 616 |
551 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 617 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
552 pStreamDict->SetAtRect("BBox", rect); | 618 pStreamDict->SetAtRect("BBox", rect); |
553 | 619 |
554 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | |
555 pResourceDict->SetAt("ExtGState", pExtGStateDict); | |
556 | |
557 pStreamDict->SetAt("Resources", pResourceDict); | 620 pStreamDict->SetAt("Resources", pResourceDict); |
558 } | 621 } |
559 | 622 |
560 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { | 623 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { |
561 if (bIsStrokeRect) | 624 if (bIsStrokeRect) |
562 return bIsFillRect ? "b" : "s"; | 625 return bIsFillRect ? "b" : "s"; |
563 return bIsFillRect ? "f" : "n"; | 626 return bIsFillRect ? "f" : "n"; |
564 } | 627 } |
565 | 628 |
566 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { | 629 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 // Fourth Bezier Curve | 798 // Fourth Bezier Curve |
736 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " | 799 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " |
737 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " | 800 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " |
738 << rect.top << " c\n"; | 801 << rect.top << " c\n"; |
739 | 802 |
740 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); | 803 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); |
741 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 804 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
742 | 805 |
743 CPDF_Dictionary* pExtGStateDict = | 806 CPDF_Dictionary* pExtGStateDict = |
744 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 807 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
745 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 808 CPDF_Dictionary* pResourceDict = |
809 GenerateResourceDict(pExtGStateDict, nullptr); | |
810 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
746 return true; | 811 return true; |
747 } | 812 } |
748 | 813 |
749 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 814 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
750 CPDF_Dictionary* pAnnotDict) { | 815 CPDF_Dictionary* pAnnotDict) { |
751 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 816 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
752 return false; | 817 return false; |
753 | 818 |
754 CFX_ByteTextBuf sAppStream; | 819 CFX_ByteTextBuf sAppStream; |
755 CFX_ByteString sExtGSDictName = "GS"; | 820 CFX_ByteString sExtGSDictName = "GS"; |
756 sAppStream << "/" << sExtGSDictName << " gs "; | 821 sAppStream << "/" << sExtGSDictName << " gs "; |
757 | 822 |
758 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 823 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
759 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 824 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
760 PaintOperation::FILL); | 825 PaintOperation::FILL); |
761 | 826 |
762 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 827 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
763 rect.Normalize(); | 828 rect.Normalize(); |
764 | 829 |
765 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " | 830 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
766 << rect.top << " l " << rect.right << " " << rect.bottom << " l " | 831 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
767 << rect.left << " " << rect.bottom << " l " | 832 << rect.left << " " << rect.bottom << " l " |
768 << "h f\n"; | 833 << "h f\n"; |
769 | 834 |
770 CPDF_Dictionary* pExtGStateDict = | 835 CPDF_Dictionary* pExtGStateDict = |
771 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); | 836 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); |
772 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 837 CPDF_Dictionary* pResourceDict = |
838 GenerateResourceDict(pExtGStateDict, nullptr); | |
839 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
773 | 840 |
774 return true; | 841 return true; |
775 } | 842 } |
776 | 843 |
777 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, | 844 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, |
778 CPDF_Dictionary* pAnnotDict) { | 845 CPDF_Dictionary* pAnnotDict) { |
779 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 846 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
780 return false; | 847 return false; |
781 | 848 |
782 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 849 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { | 884 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { |
818 sAppStream << pInkCoordList->GetNumberAt(j) << " " | 885 sAppStream << pInkCoordList->GetNumberAt(j) << " " |
819 << pInkCoordList->GetNumberAt(j + 1) << " l "; | 886 << pInkCoordList->GetNumberAt(j + 1) << " l "; |
820 } | 887 } |
821 | 888 |
822 sAppStream << "S\n"; | 889 sAppStream << "S\n"; |
823 } | 890 } |
824 | 891 |
825 CPDF_Dictionary* pExtGStateDict = | 892 CPDF_Dictionary* pExtGStateDict = |
826 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 893 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
827 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 894 CPDF_Dictionary* pResourceDict = |
895 GenerateResourceDict(pExtGStateDict, nullptr); | |
896 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
828 return true; | 897 return true; |
829 } | 898 } |
830 | 899 |
831 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, | 900 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, |
832 CPDF_Dictionary* pAnnotDict) { | 901 CPDF_Dictionary* pAnnotDict) { |
833 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 902 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
834 return false; | 903 return false; |
835 | 904 |
836 CFX_ByteTextBuf sAppStream; | 905 CFX_ByteTextBuf sAppStream; |
837 CFX_ByteString sExtGSDictName = "GS"; | 906 CFX_ByteString sExtGSDictName = "GS"; |
838 sAppStream << "/" << sExtGSDictName << " gs "; | 907 sAppStream << "/" << sExtGSDictName << " gs "; |
839 | 908 |
840 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 909 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
841 const FX_FLOAT fNoteLength = 20; | 910 const FX_FLOAT fNoteLength = 20; |
842 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, | 911 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, |
843 rect.bottom + fNoteLength); | 912 rect.bottom + fNoteLength); |
844 pAnnotDict->SetAtRect("Rect", noteRect); | 913 pAnnotDict->SetAtRect("Rect", noteRect); |
845 | 914 |
846 sAppStream << GenerateTextSymbolAP(noteRect); | 915 sAppStream << GenerateTextSymbolAP(noteRect); |
847 | 916 |
848 CPDF_Dictionary* pExtGStateDict = | 917 CPDF_Dictionary* pExtGStateDict = |
849 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 918 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
850 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 919 CPDF_Dictionary* pResourceDict = |
851 | 920 GenerateResourceDict(pExtGStateDict, nullptr); |
921 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
852 return true; | 922 return true; |
853 } | 923 } |
854 | 924 |
855 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | 925 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
856 CPDF_Dictionary* pAnnotDict) { | 926 CPDF_Dictionary* pAnnotDict) { |
857 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 927 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
858 return false; | 928 return false; |
859 | 929 |
860 CFX_ByteTextBuf sAppStream; | 930 CFX_ByteTextBuf sAppStream; |
861 CFX_ByteString sExtGSDictName = "GS"; | 931 CFX_ByteString sExtGSDictName = "GS"; |
862 sAppStream << "/" << sExtGSDictName << " gs "; | 932 sAppStream << "/" << sExtGSDictName << " gs "; |
863 | 933 |
864 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 934 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
865 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 935 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
866 PaintOperation::STROKE); | 936 PaintOperation::STROKE); |
867 | 937 |
868 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 938 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
869 rect.Normalize(); | 939 rect.Normalize(); |
870 | 940 |
871 FX_FLOAT fLineWidth = 1.0; | 941 FX_FLOAT fLineWidth = 1.0; |
872 sAppStream << fLineWidth << " w " << rect.left << " " | 942 sAppStream << fLineWidth << " w " << rect.left << " " |
873 << rect.bottom + fLineWidth << " m " << rect.right << " " | 943 << rect.bottom + fLineWidth << " m " << rect.right << " " |
874 << rect.bottom + fLineWidth << " l S\n"; | 944 << rect.bottom + fLineWidth << " l S\n"; |
875 | 945 |
876 CPDF_Dictionary* pExtGStateDict = | 946 CPDF_Dictionary* pExtGStateDict = |
877 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 947 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
878 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 948 CPDF_Dictionary* pResourceDict = |
949 GenerateResourceDict(pExtGStateDict, nullptr); | |
950 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
879 return true; | 951 return true; |
880 } | 952 } |
881 | 953 |
954 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, | |
955 CPDF_Dictionary* pAnnotDict) { | |
956 CFX_ByteTextBuf sAppStream; | |
957 CFX_ByteString sExtGSDictName = "GS"; | |
958 sAppStream << "/" << sExtGSDictName << " gs\n"; | |
959 | |
960 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | |
961 PaintOperation::FILL); | |
962 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | |
963 PaintOperation::STROKE); | |
964 | |
965 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | |
966 rect.Normalize(); | |
967 | |
968 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | |
969 << rect.Height() << " re " | |
970 << "b\n"; | |
Lei Zhang
2016/08/27 02:16:53
merge into previous line? i.e. << " re b\n";
jaepark
2016/08/29 21:19:24
Done.
| |
971 | |
972 CFX_ByteString sFontName = "FONT"; | |
973 CPDF_Dictionary* pExtGStateDict = | |
974 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | |
975 CPDF_Dictionary* pResourceFontDict = | |
976 GenerateResourceFontDict(pDoc, sFontName); | |
977 CPDF_Dictionary* pResourceDict = | |
978 GenerateResourceDict(pResourceFontDict, pExtGStateDict); | |
979 | |
980 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); | |
981 if (!pDefFont) | |
982 return false; | |
983 | |
984 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); | |
985 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
986 return true; | |
987 } | |
988 | |
882 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, | 989 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, |
883 CPDF_Dictionary* pAnnotDict) { | 990 CPDF_Dictionary* pAnnotDict) { |
884 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 991 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
885 return false; | 992 return false; |
886 | 993 |
887 CFX_ByteTextBuf sAppStream; | 994 CFX_ByteTextBuf sAppStream; |
888 CFX_ByteString sExtGSDictName = "GS"; | 995 CFX_ByteString sExtGSDictName = "GS"; |
889 sAppStream << "/" << sExtGSDictName << " gs "; | 996 sAppStream << "/" << sExtGSDictName << " gs "; |
890 | 997 |
891 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | 998 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); |
(...skipping 24 matching lines...) Expand all Loading... | |
916 } | 1023 } |
917 | 1024 |
918 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); | 1025 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); |
919 | 1026 |
920 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | 1027 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " |
921 << rect.Height() << " re " | 1028 << rect.Height() << " re " |
922 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 1029 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
923 | 1030 |
924 CPDF_Dictionary* pExtGStateDict = | 1031 CPDF_Dictionary* pExtGStateDict = |
925 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1032 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
926 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 1033 CPDF_Dictionary* pResourceDict = |
1034 GenerateResourceDict(pExtGStateDict, nullptr); | |
1035 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
927 return true; | 1036 return true; |
928 } | 1037 } |
929 | 1038 |
930 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, | 1039 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, |
931 CPDF_Dictionary* pAnnotDict) { | 1040 CPDF_Dictionary* pAnnotDict) { |
932 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 1041 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
933 return false; | 1042 return false; |
934 | 1043 |
935 CFX_ByteTextBuf sAppStream; | 1044 CFX_ByteTextBuf sAppStream; |
936 CFX_ByteString sExtGSDictName = "GS"; | 1045 CFX_ByteString sExtGSDictName = "GS"; |
(...skipping 28 matching lines...) Expand all Loading... | |
965 FX_FLOAT fRemainder = rect.right - (fX - fDelta); | 1074 FX_FLOAT fRemainder = rect.right - (fX - fDelta); |
966 if (isUpwards) | 1075 if (isUpwards) |
967 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; | 1076 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; |
968 else | 1077 else |
969 sAppStream << rect.right << " " << fTop - fRemainder << " l "; | 1078 sAppStream << rect.right << " " << fTop - fRemainder << " l "; |
970 | 1079 |
971 sAppStream << "S\n"; | 1080 sAppStream << "S\n"; |
972 | 1081 |
973 CPDF_Dictionary* pExtGStateDict = | 1082 CPDF_Dictionary* pExtGStateDict = |
974 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1083 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
975 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 1084 CPDF_Dictionary* pResourceDict = |
1085 GenerateResourceDict(pExtGStateDict, nullptr); | |
1086 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
976 return true; | 1087 return true; |
977 } | 1088 } |
978 | 1089 |
979 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, | 1090 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, |
980 CPDF_Dictionary* pAnnotDict) { | 1091 CPDF_Dictionary* pAnnotDict) { |
981 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | 1092 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
982 return false; | 1093 return false; |
983 | 1094 |
984 CFX_ByteTextBuf sAppStream; | 1095 CFX_ByteTextBuf sAppStream; |
985 CFX_ByteString sExtGSDictName = "GS"; | 1096 CFX_ByteString sExtGSDictName = "GS"; |
986 sAppStream << "/" << sExtGSDictName << " gs "; | 1097 sAppStream << "/" << sExtGSDictName << " gs "; |
987 | 1098 |
988 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 1099 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
989 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1100 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
990 PaintOperation::STROKE); | 1101 PaintOperation::STROKE); |
991 | 1102 |
992 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 1103 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
993 rect.Normalize(); | 1104 rect.Normalize(); |
994 | 1105 |
995 FX_FLOAT fLineWidth = 1.0; | 1106 FX_FLOAT fLineWidth = 1.0; |
996 FX_FLOAT fY = (rect.top + rect.bottom) / 2; | 1107 FX_FLOAT fY = (rect.top + rect.bottom) / 2; |
997 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " | 1108 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " |
998 << rect.right << " " << fY << " l S\n"; | 1109 << rect.right << " " << fY << " l S\n"; |
999 | 1110 |
1000 CPDF_Dictionary* pExtGStateDict = | 1111 CPDF_Dictionary* pExtGStateDict = |
1001 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1112 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
1002 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 1113 CPDF_Dictionary* pResourceDict = |
1114 GenerateResourceDict(pExtGStateDict, nullptr); | |
1115 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | |
1003 return true; | 1116 return true; |
1004 } | 1117 } |
1005 | 1118 |
1006 // Static. | 1119 // Static. |
1007 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 1120 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
1008 IPVT_FontMap* pFontMap, | 1121 IPVT_FontMap* pFontMap, |
1009 CPDF_VariableText::Iterator* pIterator, | 1122 CPDF_VariableText::Iterator* pIterator, |
1010 const CFX_FloatPoint& ptOffset, | 1123 const CFX_FloatPoint& ptOffset, |
1011 FX_BOOL bContinuous, | 1124 FX_BOOL bContinuous, |
1012 uint16_t SubWord) { | 1125 uint16_t SubWord) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 int32_t nFontIndex, | 1377 int32_t nFontIndex, |
1265 FX_FLOAT fFontSize) { | 1378 FX_FLOAT fFontSize) { |
1266 CFX_ByteTextBuf sRet; | 1379 CFX_ByteTextBuf sRet; |
1267 if (pFontMap) { | 1380 if (pFontMap) { |
1268 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1381 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
1269 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1382 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
1270 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1383 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
1271 } | 1384 } |
1272 return sRet.MakeString(); | 1385 return sRet.MakeString(); |
1273 } | 1386 } |
OLD | NEW |