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 20 matching lines...) Expand all Loading... |
31 CFX_ByteString DA; | 31 CFX_ByteString DA; |
32 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) | 32 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) |
33 DA = pDAObj->GetString(); | 33 DA = pDAObj->GetString(); |
34 if (DA.IsEmpty()) | 34 if (DA.IsEmpty()) |
35 DA = pFormDict->GetStringBy("DA"); | 35 DA = pFormDict->GetStringBy("DA"); |
36 if (DA.IsEmpty()) | 36 if (DA.IsEmpty()) |
37 return FALSE; | 37 return FALSE; |
38 | 38 |
39 CPDF_SimpleParser syntax(DA.AsStringC()); | 39 CPDF_SimpleParser syntax(DA.AsStringC()); |
40 syntax.FindTagParamFromStart("Tf", 2); | 40 syntax.FindTagParamFromStart("Tf", 2); |
41 CFX_ByteString sFontName = syntax.GetWord(); | 41 CFX_ByteString sFontName(syntax.GetWord()); |
42 sFontName = PDF_NameDecode(sFontName); | 42 sFontName = PDF_NameDecode(sFontName); |
43 if (sFontName.IsEmpty()) | 43 if (sFontName.IsEmpty()) |
44 return FALSE; | 44 return FALSE; |
45 | 45 |
46 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); | 46 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
47 CPVT_Color crText = CPVT_Color::ParseColor(DA); | 47 CPVT_Color crText = CPVT_Color::ParseColor(DA); |
48 FX_BOOL bUseFormRes = FALSE; | 48 FX_BOOL bUseFormRes = FALSE; |
49 CPDF_Dictionary* pFontDict = nullptr; | 49 CPDF_Dictionary* pFontDict = nullptr; |
50 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); | 50 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); |
51 if (!pDRDict) { | 51 if (!pDRDict) { |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 int32_t nCurFontIndex = -1; | 512 int32_t nCurFontIndex = -1; |
513 | 513 |
514 pIterator->SetAt(0); | 514 pIterator->SetAt(0); |
515 | 515 |
516 CPVT_WordPlace oldplace; | 516 CPVT_WordPlace oldplace; |
517 while (pIterator->NextWord()) { | 517 while (pIterator->NextWord()) { |
518 CPVT_WordPlace place = pIterator->GetAt(); | 518 CPVT_WordPlace place = pIterator->GetAt(); |
519 if (bContinuous) { | 519 if (bContinuous) { |
520 if (place.LineCmp(oldplace) != 0) { | 520 if (place.LineCmp(oldplace) != 0) { |
521 if (sWords.GetSize() > 0) { | 521 if (sWords.GetSize() > 0) { |
522 sLineStream << GetWordRenderString(sWords.AsStringC()); | 522 sLineStream << GetWordRenderString(sWords.MakeString()); |
523 sEditStream << sLineStream; | 523 sEditStream << sLineStream; |
524 sLineStream.Clear(); | 524 sLineStream.Clear(); |
525 sWords.Clear(); | 525 sWords.Clear(); |
526 } | 526 } |
527 CPVT_Word word; | 527 CPVT_Word word; |
528 if (pIterator->GetWord(word)) { | 528 if (pIterator->GetWord(word)) { |
529 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 529 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
530 word.ptWord.y + ptOffset.y); | 530 word.ptWord.y + ptOffset.y); |
531 } else { | 531 } else { |
532 CPVT_Line line; | 532 CPVT_Line line; |
533 pIterator->GetLine(line); | 533 pIterator->GetLine(line); |
534 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | 534 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, |
535 line.ptLine.y + ptOffset.y); | 535 line.ptLine.y + ptOffset.y); |
536 } | 536 } |
537 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 537 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
538 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 538 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
539 << " Td\n"; | 539 << " Td\n"; |
540 ptOld = ptNew; | 540 ptOld = ptNew; |
541 } | 541 } |
542 } | 542 } |
543 CPVT_Word word; | 543 CPVT_Word word; |
544 if (pIterator->GetWord(word)) { | 544 if (pIterator->GetWord(word)) { |
545 if (word.nFontIndex != nCurFontIndex) { | 545 if (word.nFontIndex != nCurFontIndex) { |
546 if (sWords.GetSize() > 0) { | 546 if (sWords.GetSize() > 0) { |
547 sLineStream << GetWordRenderString(sWords.AsStringC()); | 547 sLineStream << GetWordRenderString(sWords.MakeString()); |
548 sWords.Clear(); | 548 sWords.Clear(); |
549 } | 549 } |
550 sLineStream << GetFontSetString(pFontMap, word.nFontIndex, | 550 sLineStream << GetFontSetString(pFontMap, word.nFontIndex, |
551 word.fFontSize); | 551 word.fFontSize); |
552 nCurFontIndex = word.nFontIndex; | 552 nCurFontIndex = word.nFontIndex; |
553 } | 553 } |
554 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord); | 554 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord); |
555 } | 555 } |
556 oldplace = place; | 556 oldplace = place; |
557 } else { | 557 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
568 sEditStream << GetFontSetString(pFontMap, word.nFontIndex, | 568 sEditStream << GetFontSetString(pFontMap, word.nFontIndex, |
569 word.fFontSize); | 569 word.fFontSize); |
570 nCurFontIndex = word.nFontIndex; | 570 nCurFontIndex = word.nFontIndex; |
571 } | 571 } |
572 sEditStream << GetWordRenderString( | 572 sEditStream << GetWordRenderString( |
573 GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord)); | 573 GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord)); |
574 } | 574 } |
575 } | 575 } |
576 } | 576 } |
577 if (sWords.GetSize() > 0) { | 577 if (sWords.GetSize() > 0) { |
578 sLineStream << GetWordRenderString(sWords.AsStringC()); | 578 sLineStream << GetWordRenderString(sWords.MakeString()); |
579 sEditStream << sLineStream; | 579 sEditStream << sLineStream; |
580 sWords.Clear(); | 580 sWords.Clear(); |
581 } | 581 } |
582 return sEditStream.AsStringC(); | 582 return sEditStream.MakeString(); |
583 } | 583 } |
584 | 584 |
585 // Static. | 585 // Static. |
586 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( | 586 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( |
587 const CFX_FloatRect& rect, | 587 const CFX_FloatRect& rect, |
588 FX_FLOAT fWidth, | 588 FX_FLOAT fWidth, |
589 const CPVT_Color& color, | 589 const CPVT_Color& color, |
590 const CPVT_Color& crLeftTop, | 590 const CPVT_Color& crLeftTop, |
591 const CPVT_Color& crRightBottom, | 591 const CPVT_Color& crRightBottom, |
592 int32_t nStyle, | 592 int32_t nStyle, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 sColor = GenerateColorAP(color, FALSE); | 680 sColor = GenerateColorAP(color, FALSE); |
681 if (sColor.GetLength() > 0) { | 681 if (sColor.GetLength() > 0) { |
682 sAppStream << sColor; | 682 sAppStream << sColor; |
683 sAppStream << fWidth << " w\n"; | 683 sAppStream << fWidth << " w\n"; |
684 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; | 684 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; |
685 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; | 685 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; |
686 } | 686 } |
687 break; | 687 break; |
688 } | 688 } |
689 } | 689 } |
690 return sAppStream.AsStringC(); | 690 return sAppStream.MakeString(); |
691 } | 691 } |
692 | 692 |
693 // Static. | 693 // Static. |
694 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, | 694 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, |
695 const FX_BOOL& bFillOrStroke) { | 695 const FX_BOOL& bFillOrStroke) { |
696 CFX_ByteTextBuf sColorStream; | 696 CFX_ByteTextBuf sColorStream; |
697 switch (color.nColorType) { | 697 switch (color.nColorType) { |
698 case CPVT_Color::kRGB: | 698 case CPVT_Color::kRGB: |
699 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 699 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
700 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") | 700 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") |
701 << "\n"; | 701 << "\n"; |
702 break; | 702 break; |
703 case CPVT_Color::kGray: | 703 case CPVT_Color::kGray: |
704 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") | 704 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") |
705 << "\n"; | 705 << "\n"; |
706 break; | 706 break; |
707 case CPVT_Color::kCMYK: | 707 case CPVT_Color::kCMYK: |
708 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 708 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
709 << color.fColor3 << " " << color.fColor4 << " " | 709 << color.fColor3 << " " << color.fColor4 << " " |
710 << (bFillOrStroke ? "k" : "K") << "\n"; | 710 << (bFillOrStroke ? "k" : "K") << "\n"; |
711 break; | 711 break; |
712 case CPVT_Color::kTransparent: | 712 case CPVT_Color::kTransparent: |
713 break; | 713 break; |
714 } | 714 } |
715 return sColorStream.AsStringC(); | 715 return sColorStream.MakeString(); |
716 } | 716 } |
717 | 717 |
718 // Static. | 718 // Static. |
719 CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap, | 719 CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap, |
720 int32_t nFontIndex, | 720 int32_t nFontIndex, |
721 uint16_t Word, | 721 uint16_t Word, |
722 uint16_t SubWord) { | 722 uint16_t SubWord) { |
723 CFX_ByteString sWord; | 723 CFX_ByteString sWord; |
724 if (SubWord > 0) { | 724 if (SubWord > 0) { |
725 sWord.Format("%c", SubWord); | 725 sWord.Format("%c", SubWord); |
(...skipping 27 matching lines...) Expand all Loading... |
753 // Static. | 753 // Static. |
754 CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap, | 754 CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap, |
755 int32_t nFontIndex, | 755 int32_t nFontIndex, |
756 FX_FLOAT fFontSize) { | 756 FX_FLOAT fFontSize) { |
757 CFX_ByteTextBuf sRet; | 757 CFX_ByteTextBuf sRet; |
758 if (pFontMap) { | 758 if (pFontMap) { |
759 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 759 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
760 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 760 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
761 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 761 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
762 } | 762 } |
763 return sRet.AsStringC(); | 763 return sRet.MakeString(); |
764 } | 764 } |
OLD | NEW |