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

Side by Side Diff: xfa/fxfa/app/xfa_textlayout.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years 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/fxfa/app/xfa_fontmgr.cpp ('k') | xfa/fxfa/parser/cxfa_document_parser.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/fxfa/app/xfa_textlayout.h" 7 #include "xfa/fxfa/app/xfa_textlayout.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "core/fxcrt/fx_ext.h" 11 #include "core/fxcrt/fx_ext.h"
12 #include "third_party/base/ptr_util.h"
12 #include "third_party/base/stl_util.h" 13 #include "third_party/base/stl_util.h"
13 #include "xfa/fde/cfde_path.h" 14 #include "xfa/fde/cfde_path.h"
14 #include "xfa/fde/css/fde_csscache.h" 15 #include "xfa/fde/css/fde_csscache.h"
15 #include "xfa/fde/css/fde_cssstyleselector.h" 16 #include "xfa/fde/css/fde_cssstyleselector.h"
16 #include "xfa/fde/fde_gedevice.h" 17 #include "xfa/fde/fde_gedevice.h"
17 #include "xfa/fde/fde_object.h" 18 #include "xfa/fde/fde_object.h"
18 #include "xfa/fde/xml/fde_xml_imp.h" 19 #include "xfa/fde/xml/fde_xml_imp.h"
19 #include "xfa/fgas/crt/fgas_codepage.h" 20 #include "xfa/fgas/crt/fgas_codepage.h"
20 #include "xfa/fxfa/app/xfa_ffwidgetacc.h" 21 #include "xfa/fxfa/app/xfa_ffwidgetacc.h"
21 #include "xfa/fxfa/parser/cxfa_measurement.h" 22 #include "xfa/fxfa/parser/cxfa_measurement.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 m_pAllocator.reset(); 91 m_pAllocator.reset();
91 } 92 }
92 void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { 93 void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) {
93 if (!pTextProvider) 94 if (!pTextProvider)
94 return; 95 return;
95 96
96 if (!m_pSelector) { 97 if (!m_pSelector) {
97 CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); 98 CXFA_FFDoc* pDoc = pTextProvider->GetDocNode();
98 CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); 99 CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr();
99 ASSERT(pFontMgr); 100 ASSERT(pFontMgr);
100 m_pSelector.reset(new CFDE_CSSStyleSelector(pFontMgr)); 101 m_pSelector = pdfium::MakeUnique<CFDE_CSSStyleSelector>(pFontMgr);
101 FX_FLOAT fFontSize = 10; 102 FX_FLOAT fFontSize = 10;
102 CXFA_Font font = pTextProvider->GetFontNode(); 103 CXFA_Font font = pTextProvider->GetFontNode();
103 if (font) { 104 if (font) {
104 fFontSize = font.GetFontSize(); 105 fFontSize = font.GetFontSize();
105 } 106 }
106 m_pSelector->SetDefFontSize(fFontSize); 107 m_pSelector->SetDefFontSize(fFontSize);
107 } 108 }
108 if (!m_pUASheet) { 109 if (!m_pUASheet) {
109 m_pUASheet = LoadDefaultSheetStyle(); 110 m_pUASheet = LoadDefaultSheetStyle();
110 m_pSelector->SetStyleSheet(FDE_CSSSTYLESHEETGROUP_UserAgent, m_pUASheet); 111 m_pSelector->SetStyleSheet(FDE_CSSSTYLESHEETGROUP_UserAgent, m_pUASheet);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 890 }
890 } 891 }
891 m_pBreak->SetLineBoundary(fStart, fLineWidth); 892 m_pBreak->SetLineBoundary(fStart, fLineWidth);
892 FX_FLOAT fIndent = pParaStyle->GetTextIndent().GetValue(); 893 FX_FLOAT fIndent = pParaStyle->GetTextIndent().GetValue();
893 if (fIndent > 0) { 894 if (fIndent > 0) {
894 fStart += fIndent; 895 fStart += fIndent;
895 } 896 }
896 m_pBreak->SetLineStartPos(fStart); 897 m_pBreak->SetLineStartPos(fStart);
897 m_pBreak->SetTabWidth(m_textParser.GetTabInterval(pStyle)); 898 m_pBreak->SetTabWidth(m_textParser.GetTabInterval(pStyle));
898 if (!m_pTabstopContext) 899 if (!m_pTabstopContext)
899 m_pTabstopContext.reset(new CXFA_TextTabstopsContext); 900 m_pTabstopContext = pdfium::MakeUnique<CXFA_TextTabstopsContext>();
900 m_textParser.GetTabstops(pStyle, m_pTabstopContext.get()); 901 m_textParser.GetTabstops(pStyle, m_pTabstopContext.get());
901 for (int32_t i = 0; i < m_pTabstopContext->m_iTabCount; i++) { 902 for (int32_t i = 0; i < m_pTabstopContext->m_iTabCount; i++) {
902 XFA_TABSTOPS* pTab = m_pTabstopContext->m_tabstops.GetDataPtr(i); 903 XFA_TABSTOPS* pTab = m_pTabstopContext->m_tabstops.GetDataPtr(i);
903 m_pBreak->AddPositionedTab(pTab->fTabstops); 904 m_pBreak->AddPositionedTab(pTab->fTabstops);
904 } 905 }
905 } 906 }
906 FX_FLOAT fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); 907 FX_FLOAT fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle);
907 m_pBreak->SetFontSize(fFontSize); 908 m_pBreak->SetFontSize(fFontSize);
908 m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); 909 m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f);
909 m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, pStyle)); 910 m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, pStyle));
(...skipping 29 matching lines...) Expand all
939 if (fHeight < 0.1f) { 940 if (fHeight < 0.1f) {
940 fHeight = 0; 941 fHeight = 0;
941 for (int32_t i = 0; i < iCount; i++) { 942 for (int32_t i = 0; i < iCount; i++) {
942 fHeight += m_pLoader->m_lineHeights.ElementAt(i); 943 fHeight += m_pLoader->m_lineHeights.ElementAt(i);
943 } 944 }
944 } 945 }
945 return fHeight; 946 return fHeight;
946 } 947 }
947 FX_FLOAT CXFA_TextLayout::StartLayout(FX_FLOAT fWidth) { 948 FX_FLOAT CXFA_TextLayout::StartLayout(FX_FLOAT fWidth) {
948 if (!m_pLoader) 949 if (!m_pLoader)
949 m_pLoader.reset(new CXFA_LoaderContext); 950 m_pLoader = pdfium::MakeUnique<CXFA_LoaderContext>();
950 951
951 if (fWidth < 0 || (m_pLoader->m_fWidth > -1 && 952 if (fWidth < 0 || (m_pLoader->m_fWidth > -1 &&
952 FXSYS_fabs(fWidth - m_pLoader->m_fWidth) > 0)) { 953 FXSYS_fabs(fWidth - m_pLoader->m_fWidth) > 0)) {
953 m_pLoader->m_lineHeights.RemoveAll(); 954 m_pLoader->m_lineHeights.RemoveAll();
954 m_Blocks.RemoveAll(); 955 m_Blocks.RemoveAll();
955 Unload(); 956 Unload();
956 m_pLoader->m_fStartLineOffset = 0; 957 m_pLoader->m_fStartLineOffset = 0;
957 } 958 }
958 m_pLoader->m_fWidth = fWidth; 959 m_pLoader->m_fWidth = fWidth;
959 if (fWidth < 0) { 960 if (fWidth < 0) {
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 m_tabstops.RemoveAll(); 2096 m_tabstops.RemoveAll();
2096 m_iTabCount = 0; 2097 m_iTabCount = 0;
2097 } 2098 }
2098 2099
2099 void CXFA_TextTabstopsContext::Reset() { 2100 void CXFA_TextTabstopsContext::Reset() {
2100 m_iTabIndex = -1; 2101 m_iTabIndex = -1;
2101 m_bTabstops = false; 2102 m_bTabstops = false;
2102 m_fTabWidth = 0; 2103 m_fTabWidth = 0;
2103 m_fLeft = 0; 2104 m_fLeft = 0;
2104 } 2105 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_fontmgr.cpp ('k') | xfa/fxfa/parser/cxfa_document_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698