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

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: Add unique ptrs 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
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, &m_Matrix);
918 } 908 }
919 pPath->Release(); 909 delete pPath;
Wei Li 2016/05/06 22:01:21 Nit: why not use unique_ptr for pPath as well?
Tom Sepez 2016/05/11 17:05:39 Done.
920 } 910 }
921 CFDE_TTOLine::CFDE_TTOLine() 911 CFDE_TTOLine::CFDE_TTOLine()
922 : m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {} 912 : m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {}
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 }
928 CFDE_TTOLine::~CFDE_TTOLine() {} 918 CFDE_TTOLine::~CFDE_TTOLine() {}
929 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { 919 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) {
(...skipping 14 matching lines...) Expand all
944 return NULL; 934 return NULL;
945 } 935 }
946 return m_pieces.GetPtrAt(index); 936 return m_pieces.GetPtrAt(index);
947 } 937 }
948 void CFDE_TTOLine::RemoveLast(int32_t iCount) { 938 void CFDE_TTOLine::RemoveLast(int32_t iCount) {
949 m_pieces.RemoveLast(iCount); 939 m_pieces.RemoveLast(iCount);
950 } 940 }
951 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { 941 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) {
952 m_pieces.RemoveAll(bLeaveMemory); 942 m_pieces.RemoveAll(bLeaveMemory);
953 } 943 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698