Chromium Code Reviews| 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 CPDF_Dictionary* pAnnotDict) { | 605 CPDF_Dictionary* pAnnotDict) { |
| 606 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | 606 return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
| 607 } | 607 } |
| 608 | 608 |
| 609 // Static. | 609 // Static. |
| 610 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, | 610 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, |
| 611 CPDF_Dictionary* pAnnotDict) { | 611 CPDF_Dictionary* pAnnotDict) { |
| 612 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | 612 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
| 613 } | 613 } |
| 614 | 614 |
| 615 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, | |
| 616 CPDF_Dictionary* pAnnotDict) { | |
| 617 // If AP dictionary exists, we use the appearance defined in the | |
| 618 // existing AP dictionary. | |
| 619 if (pAnnotDict->KeyExist("AP")) | |
| 620 return false; | |
| 621 | |
| 622 CFX_ByteTextBuf sAppStream; | |
| 623 CFX_ByteString sExtGSDictName = "GS"; | |
| 624 sAppStream << "/" << sExtGSDictName << " gs "; | |
| 625 | |
| 626 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | |
| 627 sAppStream << GetColorStringWithDefault(pInteriorColor, | |
| 628 CPVT_Color(CPVT_Color::kTransparent), | |
| 629 PaintOperation::FILL); | |
| 630 | |
| 631 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | |
| 632 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | |
| 633 PaintOperation::STROKE); | |
| 634 | |
| 635 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | |
| 636 bool bIsStrokeRect = fBorderWidth > 0; | |
| 637 | |
| 638 if (bIsStrokeRect) { | |
| 639 sAppStream << fBorderWidth << " w "; | |
| 640 sAppStream << GetDashPatternString(*pAnnotDict); | |
| 641 } | |
| 642 | |
| 643 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | |
| 644 rect.Normalize(); | |
| 645 | |
| 646 if (bIsStrokeRect) { | |
| 647 // Deflating rect because stroking a path entails painting all points whose | |
| 648 // perpendicular distance from the path in user space is less than or equal | |
| 649 // to half the line width. | |
| 650 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); | |
| 651 } | |
| 652 | |
| 653 const FX_FLOAT fMiddleX = (rect.left + rect.right) / 2; | |
| 654 const FX_FLOAT fMiddleY = (rect.top + rect.bottom) / 2; | |
| 655 | |
| 656 // |fL| is precalculated approximate value of 4 * tan((3.14 / 2) / 4) / 3, | |
| 657 // where |fL| * radius is a good approximation of control points for | |
| 658 // arc with 90 degrees. | |
| 659 const FX_FLOAT fL = 0.5523f; | |
|
jaepark
2016/08/09 18:39:46
Fixed windows build.
| |
| 660 const FX_FLOAT fDeltaX = fL * rect.Width() / 2.0; | |
| 661 const FX_FLOAT fDeltaY = fL * rect.Height() / 2.0; | |
| 662 | |
| 663 // Starting point | |
| 664 sAppStream << fMiddleX << " " << rect.top << " m\n"; | |
| 665 // First Bezier Curve | |
| 666 sAppStream << fMiddleX + fDeltaX << " " << rect.top << " " << rect.right | |
| 667 << " " << fMiddleY + fDeltaY << " " << rect.right << " " | |
| 668 << fMiddleY << " c\n"; | |
| 669 // Second Bezier Curve | |
| 670 sAppStream << rect.right << " " << fMiddleY - fDeltaY << " " | |
| 671 << fMiddleX + fDeltaX << " " << rect.bottom << " " << fMiddleX | |
| 672 << " " << rect.bottom << " c\n"; | |
| 673 // Third Bezier Curve | |
| 674 sAppStream << fMiddleX - fDeltaX << " " << rect.bottom << " " << rect.left | |
| 675 << " " << fMiddleY - fDeltaY << " " << rect.left << " " << fMiddleY | |
| 676 << " c\n"; | |
| 677 // Fourth Bezier Curve | |
| 678 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " | |
| 679 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " | |
| 680 << rect.top << " c\n"; | |
| 681 | |
| 682 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); | |
| 683 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | |
| 684 | |
| 685 CPDF_Dictionary* pExtGStateDict = | |
| 686 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | |
| 687 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | |
| 688 return true; | |
| 689 } | |
| 690 | |
| 615 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 691 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| 616 CPDF_Dictionary* pAnnotDict) { | 692 CPDF_Dictionary* pAnnotDict) { |
| 617 // If AP dictionary exists, we use the appearance defined in the | 693 // If AP dictionary exists, we use the appearance defined in the |
| 618 // existing AP dictionary. | 694 // existing AP dictionary. |
| 619 if (pAnnotDict->KeyExist("AP")) | 695 if (pAnnotDict->KeyExist("AP")) |
| 620 return false; | 696 return false; |
| 621 | 697 |
| 622 CFX_ByteTextBuf sAppStream; | 698 CFX_ByteTextBuf sAppStream; |
| 623 CFX_ByteString sExtGSDictName = "GS"; | 699 CFX_ByteString sExtGSDictName = "GS"; |
| 624 sAppStream << "/" << sExtGSDictName << " gs "; | 700 sAppStream << "/" << sExtGSDictName << " gs "; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1062 int32_t nFontIndex, | 1138 int32_t nFontIndex, |
| 1063 FX_FLOAT fFontSize) { | 1139 FX_FLOAT fFontSize) { |
| 1064 CFX_ByteTextBuf sRet; | 1140 CFX_ByteTextBuf sRet; |
| 1065 if (pFontMap) { | 1141 if (pFontMap) { |
| 1066 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1142 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 1067 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1143 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 1068 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1144 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 1069 } | 1145 } |
| 1070 return sRet.MakeString(); | 1146 return sRet.MakeString(); |
| 1071 } | 1147 } |
| OLD | NEW |