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

Side by Side Diff: xfa/fde/tto/fde_textout.cpp

Issue 1960673003: Replace some calls to Release() with direct delete, part 1. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Another unique_ptr. Created 4 years, 7 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
« no previous file with comments | « xfa/fde/tto/fde_textout.h ('k') | xfa/fee/fde_txtedtengine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "xfa/fde/tto/fde_textout.h" 7 #include "xfa/fde/tto/fde_textout.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 22 matching lines...) Expand all
33 m_TxtColor(0xFF000000), 33 m_TxtColor(0xFF000000),
34 m_dwStyles(0), 34 m_dwStyles(0),
35 m_dwTxtBkStyles(0), 35 m_dwTxtBkStyles(0),
36 m_bElliChanged(FALSE), 36 m_bElliChanged(FALSE),
37 m_iEllipsisWidth(0), 37 m_iEllipsisWidth(0),
38 m_ttoLines(5), 38 m_ttoLines(5),
39 m_iCurLine(0), 39 m_iCurLine(0),
40 m_iCurPiece(0), 40 m_iCurPiece(0),
41 m_iTotalLines(0), 41 m_iTotalLines(0),
42 m_pCharPos(NULL), 42 m_pCharPos(NULL),
43 m_iCharPosSize(0), 43 m_iCharPosSize(0) {
44 m_pRenderDevice(NULL) {
45 m_pTxtBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); 44 m_pTxtBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None);
46 m_Matrix.SetIdentity(); 45 m_Matrix.SetIdentity();
47 m_rtClip.Reset(); 46 m_rtClip.Reset();
48 m_rtLogicClip.Reset(); 47 m_rtLogicClip.Reset();
49 } 48 }
50 CFDE_TextOut::~CFDE_TextOut() { 49 CFDE_TextOut::~CFDE_TextOut() {
51 if (m_pTxtBreak) { 50 if (m_pTxtBreak) {
52 m_pTxtBreak->Release(); 51 m_pTxtBreak->Release();
53 } 52 }
54 FX_Free(m_pCharWidths); 53 FX_Free(m_pCharWidths);
55 FX_Free(m_pEllCharWidths); 54 FX_Free(m_pEllCharWidths);
56 if (m_pRenderDevice) {
57 m_pRenderDevice->Release();
58 }
59 FX_Free(m_pCharPos); 55 FX_Free(m_pCharPos);
60 m_ttoLines.RemoveAll(); 56 m_ttoLines.RemoveAll();
61 } 57 }
62 void CFDE_TextOut::SetFont(IFX_Font* pFont) { 58 void CFDE_TextOut::SetFont(IFX_Font* pFont) {
63 ASSERT(pFont); 59 ASSERT(pFont);
64 m_pFont = pFont; 60 m_pFont = pFont;
65 m_pTxtBreak->SetFont(pFont); 61 m_pTxtBreak->SetFont(pFont);
66 } 62 }
67 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { 63 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) {
68 ASSERT(fFontSize > 0); 64 ASSERT(fFontSize > 0);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 123 }
128 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); 124 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment);
129 } 125 }
130 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { 126 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) {
131 ASSERT(fLineSpace > 1.0f); 127 ASSERT(fLineSpace > 1.0f);
132 m_fLineSpace = fLineSpace; 128 m_fLineSpace = fLineSpace;
133 } 129 }
134 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { 130 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) {
135 ASSERT(pDIB); 131 ASSERT(pDIB);
136 132
137 if (m_pRenderDevice) 133 m_pRenderDevice.reset();
138 m_pRenderDevice->Release();
139
140 CFX_FxgeDevice* device = new CFX_FxgeDevice; 134 CFX_FxgeDevice* device = new CFX_FxgeDevice;
141 device->Attach(pDIB, 0, FALSE); 135 device->Attach(pDIB, 0, FALSE);
142 m_pRenderDevice = new CFDE_RenderDevice(device, FALSE); 136 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE));
143 } 137 }
144 138
145 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { 139 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) {
146 ASSERT(pDevice); 140 ASSERT(pDevice);
147 141 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE));
148 if (m_pRenderDevice)
149 m_pRenderDevice->Release();
150
151 m_pRenderDevice = new CFDE_RenderDevice(pDevice, FALSE);
152 } 142 }
153 143
154 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { 144 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) {
155 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, 145 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top,
156 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); 146 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height());
157 } 147 }
158 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { 148 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) {
159 m_rtClip = rtClip; 149 m_rtClip = rtClip;
160 } 150 }
161 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { 151 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) {
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); 763 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j);
774 if (bVertical) { 764 if (bVertical) {
775 pPiece->rtPiece.left += fInc; 765 pPiece->rtPiece.left += fInc;
776 } else { 766 } else {
777 pPiece->rtPiece.top += fInc; 767 pPiece->rtPiece.top += fInc;
778 } 768 }
779 } 769 }
780 } 770 }
781 } 771 }
782 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { 772 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) {
783 if (m_pRenderDevice == NULL) { 773 if (!m_pRenderDevice)
784 return; 774 return;
785 } 775
786 int32_t iLines = m_ttoLines.GetSize(); 776 int32_t iLines = m_ttoLines.GetSize();
787 if (iLines < 1) { 777 if (iLines < 1)
788 return; 778 return;
789 } 779
790 CFDE_Brush* pBrush = new CFDE_Brush; 780 CFDE_Brush* pBrush = new CFDE_Brush;
791 pBrush->SetColor(m_TxtColor); 781 pBrush->SetColor(m_TxtColor);
792 CFDE_Pen* pPen = NULL; 782 CFDE_Pen* pPen = NULL;
793 FDE_HDEVICESTATE hDev = m_pRenderDevice->SaveState(); 783 FDE_HDEVICESTATE hDev = m_pRenderDevice->SaveState();
794 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { 784 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) {
795 m_pRenderDevice->SetClipRect(rtClip); 785 m_pRenderDevice->SetClipRect(rtClip);
796 } 786 }
797 for (int32_t i = 0; i < iLines; i++) { 787 for (int32_t i = 0; i < iLines; i++) {
798 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); 788 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i);
799 int32_t iPieces = pLine->GetSize(); 789 int32_t iPieces = pLine->GetSize();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 tr.wLineBreakChar = m_wParagraphBkChar; 829 tr.wLineBreakChar = m_wParagraphBkChar;
840 tr.pRect = &pPiece->rtPiece; 830 tr.pRect = &pPiece->rtPiece;
841 return tr; 831 return tr;
842 } 832 }
843 833
844 void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { 834 void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) {
845 FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); 835 FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline);
846 FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); 836 FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout);
847 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); 837 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey);
848 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); 838 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout);
849 if (!bUnderLine && !bStrikeOut && !bHotKey) { 839 if (!bUnderLine && !bStrikeOut && !bHotKey)
850 return; 840 return;
851 } 841
852 if (pPen == NULL) { 842 if (!pPen) {
853 pPen = new CFDE_Pen; 843 pPen = new CFDE_Pen;
854 pPen->SetColor(m_TxtColor); 844 pPen->SetColor(m_TxtColor);
855 } 845 }
856 CFDE_Path* pPath = new CFDE_Path; 846 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path);
857 int32_t iLineCount = 0; 847 int32_t iLineCount = 0;
858 CFX_RectF rtText = pPiece->rtPiece; 848 CFX_RectF rtText = pPiece->rtPiece;
859 CFX_PointF pt1, pt2; 849 CFX_PointF pt1, pt2;
860 if (bUnderLine) { 850 if (bUnderLine) {
861 if (bVertical) { 851 if (bVertical) {
862 pt1.x = rtText.left; 852 pt1.x = rtText.left;
863 pt1.y = rtText.top; 853 pt1.y = rtText.top;
864 pt2.x = rtText.left; 854 pt2.x = rtText.left;
865 pt2.y = rtText.bottom(); 855 pt2.y = rtText.bottom();
866 } else { 856 } else {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 pt1.y = rect.bottom(); 896 pt1.y = rect.bottom();
907 pt2.x = rect.right(); 897 pt2.x = rect.right();
908 pt2.y = rect.bottom(); 898 pt2.y = rect.bottom();
909 } 899 }
910 pPath->AddLine(pt1, pt2); 900 pPath->AddLine(pt1, pt2);
911 iLineCount++; 901 iLineCount++;
912 } 902 }
913 } 903 }
914 } 904 }
915 } 905 }
916 if (iLineCount > 0) { 906 if (iLineCount > 0)
917 m_pRenderDevice->DrawPath(pPen, 1, pPath, &m_Matrix); 907 m_pRenderDevice->DrawPath(pPen, 1, pPath.get(), &m_Matrix);
918 }
919 pPath->Release();
920 } 908 }
909
921 CFDE_TTOLine::CFDE_TTOLine() 910 CFDE_TTOLine::CFDE_TTOLine()
922 : m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {} 911 : m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {}
912
923 CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) { 913 CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) {
924 m_bNewReload = ttoLine.m_bNewReload; 914 m_bNewReload = ttoLine.m_bNewReload;
925 m_iPieceCount = ttoLine.m_iPieceCount; 915 m_iPieceCount = ttoLine.m_iPieceCount;
926 m_pieces.Copy(ttoLine.m_pieces); 916 m_pieces.Copy(ttoLine.m_pieces);
927 } 917 }
918
928 CFDE_TTOLine::~CFDE_TTOLine() {} 919 CFDE_TTOLine::~CFDE_TTOLine() {}
920
929 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { 921 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) {
930 if (index >= m_iPieceCount) { 922 if (index >= m_iPieceCount) {
931 index = m_pieces.Add(ttoPiece) + 1; 923 index = m_pieces.Add(ttoPiece) + 1;
932 m_iPieceCount++; 924 m_iPieceCount++;
933 } else { 925 } else {
934 FDE_TTOPIECE& piece = m_pieces.GetAt(index); 926 FDE_TTOPIECE& piece = m_pieces.GetAt(index);
935 piece = ttoPiece; 927 piece = ttoPiece;
936 } 928 }
937 return index; 929 return index;
938 } 930 }
939 int32_t CFDE_TTOLine::GetSize() const { 931 int32_t CFDE_TTOLine::GetSize() const {
940 return m_iPieceCount; 932 return m_iPieceCount;
941 } 933 }
942 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { 934 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) {
943 if (index >= m_iPieceCount) { 935 if (index >= m_iPieceCount) {
944 return NULL; 936 return NULL;
945 } 937 }
946 return m_pieces.GetPtrAt(index); 938 return m_pieces.GetPtrAt(index);
947 } 939 }
948 void CFDE_TTOLine::RemoveLast(int32_t iCount) { 940 void CFDE_TTOLine::RemoveLast(int32_t iCount) {
949 m_pieces.RemoveLast(iCount); 941 m_pieces.RemoveLast(iCount);
950 } 942 }
951 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { 943 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) {
952 m_pieces.RemoveAll(bLeaveMemory); 944 m_pieces.RemoveAll(bLeaveMemory);
953 } 945 }
OLDNEW
« no previous file with comments | « xfa/fde/tto/fde_textout.h ('k') | xfa/fee/fde_txtedtengine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698