Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2273893002: Display content of the annotation when mouse hover. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Removing useless comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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: ");
517 swValue += pAnnotDict.GetUnicodeTextBy("T");
518 swValue += L'\n';
519 swValue += pAnnotDict.GetUnicodeTextBy("Contents");
520 CPVT_FontMap map(pDoc, nullptr, pDefFont,
521 sFontName.Right(sFontName.GetLength() - 1));
522
523 CPDF_VariableText vt;
524 CPDF_VariableText::Provider prd(&map);
525 vt.SetProvider(&prd);
526 CFX_FloatRect rect = pAnnotDict.GetRectBy("Rect");
527 vt.SetPlateRect(rect);
528 vt.SetFontSize(12);
529 vt.SetAutoReturn(TRUE);
530 vt.SetMultiLine(TRUE);
531
532 vt.Initialize();
533 vt.SetText(swValue.c_str());
534 vt.RearrangeAll();
535 CFX_FloatRect rcContent = vt.GetContentRect();
536 CFX_FloatPoint ptOffset =
537 CFX_FloatPoint(0.0f, (rcContent.Height() - rect.Height()) / 2.0f);
538 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP(
539 &map, vt.GetIterator(), ptOffset, FALSE, 0);
540
541 if (sContent.IsEmpty())
542 return CFX_ByteString();
543
544 CFX_ByteTextBuf sAppStream;
545 sAppStream << "BT\n"
546 << CPVT_GenerateAP::GenerateColorAP(
547 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL)
548 << sContent << "ET\n"
549 << "Q\n";
550 return sAppStream.MakeString();
551 }
552
512 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, 553 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
513 const CFX_ByteString& sExtGSDictName, 554 const CFX_ByteString& sExtGSDictName,
514 const CFX_ByteString& sBlendMode) { 555 const CFX_ByteString& sBlendMode) {
515 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; 556 CPDF_Dictionary* pGSDict = new CPDF_Dictionary;
516 pGSDict->SetAtString("Type", "ExtGState"); 557 pGSDict->SetAtString("Type", "ExtGState");
517 558
518 FX_FLOAT fOpacity = 559 FX_FLOAT fOpacity =
519 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1; 560 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1;
520 pGSDict->SetAtNumber("CA", fOpacity); 561 pGSDict->SetAtNumber("CA", fOpacity);
521 pGSDict->SetAtNumber("ca", fOpacity); 562 pGSDict->SetAtNumber("ca", fOpacity);
522 pGSDict->SetAtBoolean("AIS", false); 563 pGSDict->SetAtBoolean("AIS", false);
523 pGSDict->SetAtString("BM", sBlendMode); 564 pGSDict->SetAtString("BM", sBlendMode);
524 565
525 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; 566 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
526 pExtGStateDict->SetAt(sExtGSDictName, pGSDict); 567 pExtGStateDict->SetAt(sExtGSDictName, pGSDict);
527 568
528 return pExtGStateDict; 569 return pExtGStateDict;
529 } 570 }
530 571
531 // Takes ownership of |pExtGStateDict|. 572 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
dsinclair 2016/08/24 14:00:20 std::unique_ptr?
jaepark 2016/08/24 18:37:48 This is a dictionary that should be set as a key o
573 const CFX_ByteString& sFontDictName) {
574 CPDF_Dictionary* pFontDict = new CPDF_Dictionary;
575 pFontDict->SetAtName("Type", "Font");
576 pFontDict->SetAtName("Subtype", "Type1");
577 pFontDict->SetAtName("BaseFont", "Helvetica");
578 pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
dsinclair 2016/08/24 14:00:20 Are these settings spec, or just created? If creat
jaepark 2016/08/24 18:37:48 These are just created. I referred to line 69~77 o
579 pDoc->AddIndirectObject(pFontDict);
580
581 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary;
582 pResourceFontDict->SetAtReference(sFontDictName, pDoc, pFontDict);
583
584 return pResourceFontDict;
585 }
586
587 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|.
588 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict,
dsinclair 2016/08/24 14:00:20 Pass in a std::unique_ptr to show the transfer? (a
jaepark 2016/08/24 18:37:48 Same as above. CPDF_Dictionary takes a raw pointer
589 CPDF_Dictionary* pResourceFontDict) {
590 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
591 if (pExtGStateDict)
592 pResourceDict->SetAt("ExtGState", pExtGStateDict);
593
594 if (pResourceFontDict)
595 pResourceDict->SetAt("Font", pResourceFontDict);
596
597 return pResourceDict;
598 }
599
600 // Takes ownership of |pResourceDict|.
532 void GenerateAndSetAPDict(CPDF_Document* pDoc, 601 void GenerateAndSetAPDict(CPDF_Document* pDoc,
533 CPDF_Dictionary* pAnnotDict, 602 CPDF_Dictionary* pAnnotDict,
534 const CFX_ByteTextBuf& sAppStream, 603 const CFX_ByteTextBuf& sAppStream,
535 CPDF_Dictionary* pExtGStateDict) { 604 CPDF_Dictionary* pResourceDict) {
536 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; 605 CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
537 pAnnotDict->SetAt("AP", pAPDict); 606 pAnnotDict->SetAt("AP", pAPDict);
538 607
539 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 608 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
540 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 609 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
541 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); 610 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum);
542 611
543 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, 612 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE,
544 FALSE); 613 FALSE);
545 614
546 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 615 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
547 pStreamDict->SetAtInteger("FormType", 1); 616 pStreamDict->SetAtInteger("FormType", 1);
548 pStreamDict->SetAtString("Subtype", "Form"); 617 pStreamDict->SetAtString("Subtype", "Form");
549 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); 618 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix());
550 619
551 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 620 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
552 pStreamDict->SetAtRect("BBox", rect); 621 pStreamDict->SetAtRect("BBox", rect);
553 622
554 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
555 pResourceDict->SetAt("ExtGState", pExtGStateDict);
556
557 pStreamDict->SetAt("Resources", pResourceDict); 623 pStreamDict->SetAt("Resources", pResourceDict);
558 } 624 }
559 625
560 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { 626 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
561 if (bIsStrokeRect) 627 if (bIsStrokeRect)
562 return bIsFillRect ? "b" : "s"; 628 return bIsFillRect ? "b" : "s";
563 return bIsFillRect ? "f" : "n"; 629 return bIsFillRect ? "f" : "n";
564 } 630 }
565 631
566 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { 632 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // Fourth Bezier Curve 801 // Fourth Bezier Curve
736 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " 802 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " "
737 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " 803 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " "
738 << rect.top << " c\n"; 804 << rect.top << " c\n";
739 805
740 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); 806 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty();
741 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 807 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
742 808
743 CPDF_Dictionary* pExtGStateDict = 809 CPDF_Dictionary* pExtGStateDict =
744 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 810 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
745 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 811 CPDF_Dictionary* pResourceDict =
812 GenerateResourceDict(pExtGStateDict, nullptr);
813 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
746 return true; 814 return true;
747 } 815 }
748 816
749 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 817 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
750 CPDF_Dictionary* pAnnotDict) { 818 CPDF_Dictionary* pAnnotDict) {
751 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 819 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
752 return false; 820 return false;
753 821
754 CFX_ByteTextBuf sAppStream; 822 CFX_ByteTextBuf sAppStream;
755 CFX_ByteString sExtGSDictName = "GS"; 823 CFX_ByteString sExtGSDictName = "GS";
756 sAppStream << "/" << sExtGSDictName << " gs "; 824 sAppStream << "/" << sExtGSDictName << " gs ";
757 825
758 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 826 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
759 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 827 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
760 PaintOperation::FILL); 828 PaintOperation::FILL);
761 829
762 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 830 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
763 rect.Normalize(); 831 rect.Normalize();
764 832
765 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " 833 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
766 << rect.top << " l " << rect.right << " " << rect.bottom << " l " 834 << rect.top << " l " << rect.right << " " << rect.bottom << " l "
767 << rect.left << " " << rect.bottom << " l " 835 << rect.left << " " << rect.bottom << " l "
768 << "h f\n"; 836 << "h f\n";
769 837
770 CPDF_Dictionary* pExtGStateDict = 838 CPDF_Dictionary* pExtGStateDict =
771 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); 839 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
772 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 840 CPDF_Dictionary* pResourceDict =
841 GenerateResourceDict(pExtGStateDict, nullptr);
842 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
773 843
774 return true; 844 return true;
775 } 845 }
776 846
777 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 847 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
778 CPDF_Dictionary* pAnnotDict) { 848 CPDF_Dictionary* pAnnotDict) {
779 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 849 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
780 return false; 850 return false;
781 851
782 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 852 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { 887 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) {
818 sAppStream << pInkCoordList->GetNumberAt(j) << " " 888 sAppStream << pInkCoordList->GetNumberAt(j) << " "
819 << pInkCoordList->GetNumberAt(j + 1) << " l "; 889 << pInkCoordList->GetNumberAt(j + 1) << " l ";
820 } 890 }
821 891
822 sAppStream << "S\n"; 892 sAppStream << "S\n";
823 } 893 }
824 894
825 CPDF_Dictionary* pExtGStateDict = 895 CPDF_Dictionary* pExtGStateDict =
826 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 896 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
827 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 897 CPDF_Dictionary* pResourceDict =
898 GenerateResourceDict(pExtGStateDict, nullptr);
899 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
828 return true; 900 return true;
829 } 901 }
830 902
831 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, 903 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
832 CPDF_Dictionary* pAnnotDict) { 904 CPDF_Dictionary* pAnnotDict) {
833 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 905 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
834 return false; 906 return false;
835 907
836 CFX_ByteTextBuf sAppStream; 908 CFX_ByteTextBuf sAppStream;
837 CFX_ByteString sExtGSDictName = "GS"; 909 CFX_ByteString sExtGSDictName = "GS";
838 sAppStream << "/" << sExtGSDictName << " gs "; 910 sAppStream << "/" << sExtGSDictName << " gs ";
839 911
840 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 912 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
841 const FX_FLOAT fNoteLength = 20; 913 const FX_FLOAT fNoteLength = 20;
842 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, 914 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
843 rect.bottom + fNoteLength); 915 rect.bottom + fNoteLength);
844 pAnnotDict->SetAtRect("Rect", noteRect); 916 pAnnotDict->SetAtRect("Rect", noteRect);
845 917
846 sAppStream << GenerateTextSymbolAP(noteRect); 918 sAppStream << GenerateTextSymbolAP(noteRect);
847 919
848 CPDF_Dictionary* pExtGStateDict = 920 CPDF_Dictionary* pExtGStateDict =
849 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 921 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
850 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 922 CPDF_Dictionary* pResourceDict =
851 923 GenerateResourceDict(pExtGStateDict, nullptr);
924 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
852 return true; 925 return true;
853 } 926 }
854 927
855 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 928 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
856 CPDF_Dictionary* pAnnotDict) { 929 CPDF_Dictionary* pAnnotDict) {
857 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 930 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
858 return false; 931 return false;
859 932
860 CFX_ByteTextBuf sAppStream; 933 CFX_ByteTextBuf sAppStream;
861 CFX_ByteString sExtGSDictName = "GS"; 934 CFX_ByteString sExtGSDictName = "GS";
862 sAppStream << "/" << sExtGSDictName << " gs "; 935 sAppStream << "/" << sExtGSDictName << " gs ";
863 936
864 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 937 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
865 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 938 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
866 PaintOperation::STROKE); 939 PaintOperation::STROKE);
867 940
868 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 941 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
869 rect.Normalize(); 942 rect.Normalize();
870 943
871 FX_FLOAT fLineWidth = 1.0; 944 FX_FLOAT fLineWidth = 1.0;
872 sAppStream << fLineWidth << " w " << rect.left << " " 945 sAppStream << fLineWidth << " w " << rect.left << " "
873 << rect.bottom + fLineWidth << " m " << rect.right << " " 946 << rect.bottom + fLineWidth << " m " << rect.right << " "
874 << rect.bottom + fLineWidth << " l S\n"; 947 << rect.bottom + fLineWidth << " l S\n";
875 948
876 CPDF_Dictionary* pExtGStateDict = 949 CPDF_Dictionary* pExtGStateDict =
877 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 950 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
878 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 951 CPDF_Dictionary* pResourceDict =
952 GenerateResourceDict(pExtGStateDict, nullptr);
953 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
879 return true; 954 return true;
880 } 955 }
881 956
957 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
958 CPDF_Dictionary* pAnnotDict) {
959 CFX_ByteTextBuf sAppStream;
960 CFX_ByteString sExtGSDictName = "GS";
961 sAppStream << "/" << sExtGSDictName << " gs\n";
962
963 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
964 PaintOperation::FILL);
965 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
966 PaintOperation::STROKE);
967
968 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
969 rect.Normalize();
970
971 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
972 << rect.Height() << " re "
973 << "b\n";
974
975 CFX_ByteString sFontName = "/FONT";
976 CPDF_Dictionary* pExtGStateDict =
977 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
978 CPDF_Dictionary* pResourceFontDict =
979 GenerateResourceFontDict(pDoc, sFontName);
980 CPDF_Dictionary* pResourceDict =
981 GenerateResourceDict(pResourceFontDict, pExtGStateDict);
982
983 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict);
984 if (!pDefFont)
985 return false;
986
987 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName);
988 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
989 return true;
990 }
991
882 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, 992 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
883 CPDF_Dictionary* pAnnotDict) { 993 CPDF_Dictionary* pAnnotDict) {
884 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 994 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
885 return false; 995 return false;
886 996
887 CFX_ByteTextBuf sAppStream; 997 CFX_ByteTextBuf sAppStream;
888 CFX_ByteString sExtGSDictName = "GS"; 998 CFX_ByteString sExtGSDictName = "GS";
889 sAppStream << "/" << sExtGSDictName << " gs "; 999 sAppStream << "/" << sExtGSDictName << " gs ";
890 1000
891 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 1001 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
(...skipping 24 matching lines...) Expand all
916 } 1026 }
917 1027
918 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); 1028 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0);
919 1029
920 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " 1030 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
921 << rect.Height() << " re " 1031 << rect.Height() << " re "
922 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 1032 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
923 1033
924 CPDF_Dictionary* pExtGStateDict = 1034 CPDF_Dictionary* pExtGStateDict =
925 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1035 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
926 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 1036 CPDF_Dictionary* pResourceDict =
1037 GenerateResourceDict(pExtGStateDict, nullptr);
1038 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
927 return true; 1039 return true;
928 } 1040 }
929 1041
930 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 1042 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
931 CPDF_Dictionary* pAnnotDict) { 1043 CPDF_Dictionary* pAnnotDict) {
932 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 1044 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
933 return false; 1045 return false;
934 1046
935 CFX_ByteTextBuf sAppStream; 1047 CFX_ByteTextBuf sAppStream;
936 CFX_ByteString sExtGSDictName = "GS"; 1048 CFX_ByteString sExtGSDictName = "GS";
(...skipping 28 matching lines...) Expand all
965 FX_FLOAT fRemainder = rect.right - (fX - fDelta); 1077 FX_FLOAT fRemainder = rect.right - (fX - fDelta);
966 if (isUpwards) 1078 if (isUpwards)
967 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; 1079 sAppStream << rect.right << " " << fBottom + fRemainder << " l ";
968 else 1080 else
969 sAppStream << rect.right << " " << fTop - fRemainder << " l "; 1081 sAppStream << rect.right << " " << fTop - fRemainder << " l ";
970 1082
971 sAppStream << "S\n"; 1083 sAppStream << "S\n";
972 1084
973 CPDF_Dictionary* pExtGStateDict = 1085 CPDF_Dictionary* pExtGStateDict =
974 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1086 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
975 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 1087 CPDF_Dictionary* pResourceDict =
1088 GenerateResourceDict(pExtGStateDict, nullptr);
1089 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
976 return true; 1090 return true;
977 } 1091 }
978 1092
979 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 1093 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
980 CPDF_Dictionary* pAnnotDict) { 1094 CPDF_Dictionary* pAnnotDict) {
981 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 1095 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
982 return false; 1096 return false;
983 1097
984 CFX_ByteTextBuf sAppStream; 1098 CFX_ByteTextBuf sAppStream;
985 CFX_ByteString sExtGSDictName = "GS"; 1099 CFX_ByteString sExtGSDictName = "GS";
986 sAppStream << "/" << sExtGSDictName << " gs "; 1100 sAppStream << "/" << sExtGSDictName << " gs ";
987 1101
988 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 1102 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
989 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 1103 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
990 PaintOperation::STROKE); 1104 PaintOperation::STROKE);
991 1105
992 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 1106 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
993 rect.Normalize(); 1107 rect.Normalize();
994 1108
995 FX_FLOAT fLineWidth = 1.0; 1109 FX_FLOAT fLineWidth = 1.0;
996 FX_FLOAT fY = (rect.top + rect.bottom) / 2; 1110 FX_FLOAT fY = (rect.top + rect.bottom) / 2;
997 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " 1111 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m "
998 << rect.right << " " << fY << " l S\n"; 1112 << rect.right << " " << fY << " l S\n";
999 1113
1000 CPDF_Dictionary* pExtGStateDict = 1114 CPDF_Dictionary* pExtGStateDict =
1001 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1115 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1002 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 1116 CPDF_Dictionary* pResourceDict =
1117 GenerateResourceDict(pExtGStateDict, nullptr);
1118 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
1003 return true; 1119 return true;
1004 } 1120 }
1005 1121
1006 // Static. 1122 // Static.
1007 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 1123 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
1008 IPVT_FontMap* pFontMap, 1124 IPVT_FontMap* pFontMap,
1009 CPDF_VariableText::Iterator* pIterator, 1125 CPDF_VariableText::Iterator* pIterator,
1010 const CFX_FloatPoint& ptOffset, 1126 const CFX_FloatPoint& ptOffset,
1011 FX_BOOL bContinuous, 1127 FX_BOOL bContinuous,
1012 uint16_t SubWord) { 1128 uint16_t SubWord) {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 int32_t nFontIndex, 1380 int32_t nFontIndex,
1265 FX_FLOAT fFontSize) { 1381 FX_FLOAT fFontSize) {
1266 CFX_ByteTextBuf sRet; 1382 CFX_ByteTextBuf sRet;
1267 if (pFontMap) { 1383 if (pFontMap) {
1268 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1384 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1269 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1385 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1270 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1386 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1271 } 1387 }
1272 return sRet.MakeString(); 1388 return sRet.MakeString();
1273 } 1389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698