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

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_text.cpp

Issue 2013023002: Clean up CPDF_TextRenderer slightly. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@fxgeclean2
Patch Set: rebase Created 4 years, 6 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 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 "core/fpdfapi/fpdf_render/render_int.h" 7 #include "core/fpdfapi/fpdf_render/render_int.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 FX_FLOAT* pCharPos, 521 FX_FLOAT* pCharPos,
522 CPDF_Font* pFont, 522 CPDF_Font* pFont,
523 FX_FLOAT font_size); 523 FX_FLOAT font_size);
524 FXTEXT_CHARPOS* m_pCharPos; 524 FXTEXT_CHARPOS* m_pCharPos;
525 uint32_t m_nChars; 525 uint32_t m_nChars;
526 }; 526 };
527 527
528 CPDF_CharPosList::CPDF_CharPosList() { 528 CPDF_CharPosList::CPDF_CharPosList() {
529 m_pCharPos = NULL; 529 m_pCharPos = NULL;
530 } 530 }
531
531 CPDF_CharPosList::~CPDF_CharPosList() { 532 CPDF_CharPosList::~CPDF_CharPosList() {
532 FX_Free(m_pCharPos); 533 FX_Free(m_pCharPos);
533 } 534 }
535
534 void CPDF_CharPosList::Load(int nChars, 536 void CPDF_CharPosList::Load(int nChars,
535 uint32_t* pCharCodes, 537 uint32_t* pCharCodes,
536 FX_FLOAT* pCharPos, 538 FX_FLOAT* pCharPos,
537 CPDF_Font* pFont, 539 CPDF_Font* pFont,
538 FX_FLOAT FontSize) { 540 FX_FLOAT FontSize) {
539 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars); 541 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars);
540 m_nChars = 0; 542 m_nChars = 0;
541 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); 543 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
542 FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting(); 544 FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting();
543 for (int iChar = 0; iChar < nChars; iChar++) { 545 for (int iChar = 0; iChar < nChars; iChar++) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 charpos.m_AdjustMatrix[3] = pCIDFont->CIDTransformToFloat(pTransform[3]); 585 charpos.m_AdjustMatrix[3] = pCIDFont->CIDTransformToFloat(pTransform[3]);
584 charpos.m_OriginX += 586 charpos.m_OriginX +=
585 pCIDFont->CIDTransformToFloat(pTransform[4]) * FontSize; 587 pCIDFont->CIDTransformToFloat(pTransform[4]) * FontSize;
586 charpos.m_OriginY += 588 charpos.m_OriginY +=
587 pCIDFont->CIDTransformToFloat(pTransform[5]) * FontSize; 589 pCIDFont->CIDTransformToFloat(pTransform[5]) * FontSize;
588 charpos.m_bGlyphAdjust = TRUE; 590 charpos.m_bGlyphAdjust = TRUE;
589 } 591 }
590 } 592 }
591 } 593 }
592 594
595 // static
593 FX_BOOL CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice, 596 FX_BOOL CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
594 int nChars, 597 int nChars,
595 uint32_t* pCharCodes, 598 uint32_t* pCharCodes,
596 FX_FLOAT* pCharPos, 599 FX_FLOAT* pCharPos,
597 CPDF_Font* pFont, 600 CPDF_Font* pFont,
598 FX_FLOAT font_size, 601 FX_FLOAT font_size,
599 const CFX_Matrix* pText2User, 602 const CFX_Matrix* pText2User,
600 const CFX_Matrix* pUser2Device, 603 const CFX_Matrix* pUser2Device,
601 const CFX_GraphStateData* pGraphState, 604 const CFX_GraphStateData* pGraphState,
602 FX_ARGB fill_argb, 605 FX_ARGB fill_argb,
603 FX_ARGB stroke_argb, 606 FX_ARGB stroke_argb,
604 CFX_PathData* pClippingPath, 607 CFX_PathData* pClippingPath,
605 int nFlag) { 608 int nFlag) {
606 CFX_FontCache* pCache = 609 CFX_FontCache* pCache =
607 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() 610 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache()
608 : nullptr; 611 : nullptr;
609 CPDF_CharPosList CharPosList; 612 CPDF_CharPosList CharPosList;
610 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); 613 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
611 return pDevice->DrawTextPathWithFlags( 614 return pDevice->DrawTextPathWithFlags(
612 CharPosList.m_nChars, CharPosList.m_pCharPos, &pFont->m_Font, pCache, 615 CharPosList.m_nChars, CharPosList.m_pCharPos, &pFont->m_Font, pCache,
613 font_size, pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb, 616 font_size, pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb,
614 pClippingPath, nFlag); 617 pClippingPath, nFlag);
615 } 618 }
616 619
617 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, 620 // static
618 int left,
619 int top,
620 CPDF_Font* pFont,
621 int height,
622 const CFX_ByteString& str,
623 FX_ARGB argb) {
624 FX_RECT font_bbox;
625 pFont->GetFontBBox(font_bbox);
626 FX_FLOAT font_size =
627 (FX_FLOAT)height * 1000.0f / (FX_FLOAT)(font_bbox.top - font_bbox.bottom);
628 FX_FLOAT origin_x = (FX_FLOAT)left;
629 FX_FLOAT origin_y =
630 (FX_FLOAT)top + font_size * (FX_FLOAT)font_bbox.top / 1000.0f;
631 CFX_Matrix matrix(1.0f, 0, 0, -1.0f, 0, 0);
632 DrawTextString(pDevice, origin_x, origin_y, pFont, font_size, &matrix, str,
633 argb);
634 }
635 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, 621 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
636 FX_FLOAT origin_x, 622 FX_FLOAT origin_x,
637 FX_FLOAT origin_y, 623 FX_FLOAT origin_y,
638 CPDF_Font* pFont, 624 CPDF_Font* pFont,
639 FX_FLOAT font_size, 625 FX_FLOAT font_size,
640 const CFX_Matrix* pMatrix, 626 const CFX_Matrix* pMatrix,
641 const CFX_ByteString& str, 627 const CFX_ByteString& str,
642 FX_ARGB fill_argb, 628 FX_ARGB fill_argb,
643 FX_ARGB stroke_argb, 629 FX_ARGB stroke_argb,
644 const CFX_GraphStateData* pGraphState, 630 const CFX_GraphStateData* pGraphState,
(...skipping 28 matching lines...) Expand all
673 659
674 matrix.e = origin_x; 660 matrix.e = origin_x;
675 matrix.f = origin_y; 661 matrix.f = origin_y;
676 662
677 if (!pFont->IsType3Font()) { 663 if (!pFont->IsType3Font()) {
678 if (stroke_argb == 0) { 664 if (stroke_argb == 0) {
679 DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, 665 DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size,
680 &matrix, fill_argb, pOptions); 666 &matrix, fill_argb, pOptions);
681 } else { 667 } else {
682 DrawTextPath(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, 668 DrawTextPath(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size,
683 &matrix, NULL, pGraphState, fill_argb, stroke_argb, NULL); 669 &matrix, nullptr, pGraphState, fill_argb, stroke_argb,
670 nullptr, 0);
684 } 671 }
685 } 672 }
686 673
687 if (nChars > 1) { 674 if (nChars > 1) {
688 FX_Free(pCharCodes); 675 FX_Free(pCharCodes);
689 FX_Free(pCharPos); 676 FX_Free(pCharPos);
690 } 677 }
691 } 678 }
679
680 // static
692 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, 681 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
693 int nChars, 682 int nChars,
694 uint32_t* pCharCodes, 683 uint32_t* pCharCodes,
695 FX_FLOAT* pCharPos, 684 FX_FLOAT* pCharPos,
696 CPDF_Font* pFont, 685 CPDF_Font* pFont,
697 FX_FLOAT font_size, 686 FX_FLOAT font_size,
698 const CFX_Matrix* pText2Device, 687 const CFX_Matrix* pText2Device,
699 FX_ARGB fill_argb, 688 FX_ARGB fill_argb,
700 const CPDF_RenderOptions* pOptions) { 689 const CPDF_RenderOptions* pOptions) {
701 CFX_FontCache* pCache = 690 CFX_FontCache* pCache =
(...skipping 25 matching lines...) Expand all
727 } else { 716 } else {
728 FXGE_flags = FXTEXT_CLEARTYPE; 717 FXGE_flags = FXTEXT_CLEARTYPE;
729 } 718 }
730 if (pFont->IsCIDFont()) { 719 if (pFont->IsCIDFont()) {
731 FXGE_flags |= FXFONT_CIDFONT; 720 FXGE_flags |= FXFONT_CIDFONT;
732 } 721 }
733 return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos, 722 return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos,
734 &pFont->m_Font, pCache, font_size, 723 &pFont->m_Font, pCache, font_size,
735 pText2Device, fill_argb, FXGE_flags); 724 pText2Device, fill_argb, FXGE_flags);
736 } 725 }
726
737 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, 727 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
738 const CFX_Matrix* pObj2Device, 728 const CFX_Matrix* pObj2Device,
739 CPDF_Font* pFont, 729 CPDF_Font* pFont,
740 FX_FLOAT font_size, 730 FX_FLOAT font_size,
741 const CFX_Matrix* pTextMatrix, 731 const CFX_Matrix* pTextMatrix,
742 FX_BOOL bFill, 732 FX_BOOL bFill,
743 FX_BOOL bStroke) { 733 FX_BOOL bStroke) {
744 if (!bStroke) { 734 if (!bStroke) {
745 CPDF_PathObject path; 735 CPDF_PathObject path;
746 std::vector<std::unique_ptr<CPDF_TextObject>> pCopy; 736 std::vector<std::unique_ptr<CPDF_TextObject>> pCopy;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 776 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
787 charpos.m_OriginY); 777 charpos.m_OriginY);
788 path.m_Path.New()->Append(pPath, &matrix); 778 path.m_Path.New()->Append(pPath, &matrix);
789 path.m_Matrix = *pTextMatrix; 779 path.m_Matrix = *pTextMatrix;
790 path.m_bStroke = bStroke; 780 path.m_bStroke = bStroke;
791 path.m_FillType = bFill ? FXFILL_WINDING : 0; 781 path.m_FillType = bFill ? FXFILL_WINDING : 0;
792 path.CalcBoundingBox(); 782 path.CalcBoundingBox();
793 ProcessPath(&path, pObj2Device); 783 ProcessPath(&path, pObj2Device);
794 } 784 }
795 } 785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698