From 6c0c48227aa024aa6e188ed7adf4d7c3d410cff9 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 10 Jan 2017 13:40:26 -0800 Subject: Remove CFX_ArrayTemplate in cfx_psrender. Use unique_ptr while we're at it. Review-Url: https://codereview.chromium.org/2618373003 --- core/fxge/win32/cfx_psrenderer.cpp | 77 ++++++++++++++++++-------------------- core/fxge/win32/cfx_psrenderer.h | 7 +++- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 0cd24faf83..c0d7557541 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -16,6 +16,7 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/ge/fx_text_int.h" #include "core/fxge/win32/cpsoutput.h" +#include "third_party/base/ptr_util.h" struct PSGlyph { CFX_Font* m_pFont; @@ -36,12 +37,7 @@ CFX_PSRenderer::CFX_PSRenderer() { m_bInited = false; } -CFX_PSRenderer::~CFX_PSRenderer() { - for (int i = 0; i < static_cast(m_PSFontList.GetSize()); i++) { - CPSFont* pFont = m_PSFontList[i]; - delete pFont; - } -} +CFX_PSRenderer::~CFX_PSRenderer() {} #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str - 1) @@ -84,32 +80,31 @@ bool CFX_PSRenderer::StartRendering() { void CFX_PSRenderer::EndRendering() { if (m_bInited) { OUTPUT_PS("\nrestore\n"); + m_bInited = false; } - m_bInited = false; } void CFX_PSRenderer::SaveState() { StartRendering(); OUTPUT_PS("q\n"); - m_ClipBoxStack.Add(m_ClipBox); + m_ClipBoxStack.push_back(m_ClipBox); } void CFX_PSRenderer::RestoreState(bool bKeepSaved) { StartRendering(); - if (bKeepSaved) { + if (bKeepSaved) OUTPUT_PS("Q\nq\n"); - } else { + else OUTPUT_PS("Q\n"); - } + m_bColorSet = false; m_bGraphStateSet = false; - int size = m_ClipBoxStack.GetSize(); - if (!size) + if (m_ClipBoxStack.empty()) return; - m_ClipBox = m_ClipBoxStack.GetAt(size - 1); + m_ClipBox = m_ClipBoxStack.back(); if (!bKeepSaved) - m_ClipBoxStack.RemoveAt(size - 1); + m_ClipBoxStack.pop_back(); } void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, @@ -537,32 +532,31 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, const FXTEXT_CHARPOS& charpos, int* ps_fontnum, int* ps_glyphindex) { - for (int i = 0; i < m_PSFontList.GetSize(); i++) { - CPSFont* pPSFont = m_PSFontList[i]; - for (int j = 0; j < pPSFont->m_nGlyphs; j++) + int i = 0; + for (const auto& pPSFont : m_PSFontList) { + for (int j = 0; j < pPSFont->m_nGlyphs; j++) { if (pPSFont->m_Glyphs[j].m_pFont == pFont && - pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex) { - if ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || - (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && - (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - - charpos.m_AdjustMatrix[0]) < 0.01 && - FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - - charpos.m_AdjustMatrix[1]) < 0.01 && - FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - - charpos.m_AdjustMatrix[2]) < 0.01 && - FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - - charpos.m_AdjustMatrix[3]) < 0.01))) { - *ps_fontnum = i; - *ps_glyphindex = j; - return; - } + pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex && + ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || + (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && + (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - + charpos.m_AdjustMatrix[0]) < 0.01 && + FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - + charpos.m_AdjustMatrix[1]) < 0.01 && + FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - + charpos.m_AdjustMatrix[2]) < 0.01 && + FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - + charpos.m_AdjustMatrix[3]) < 0.01)))) { + *ps_fontnum = i; + *ps_glyphindex = j; + return; } + } + ++i; } - if (m_PSFontList.GetSize() == 0 || - m_PSFontList[m_PSFontList.GetSize() - 1]->m_nGlyphs == 256) { - CPSFont* pPSFont = new CPSFont; - pPSFont->m_nGlyphs = 0; - m_PSFontList.Add(pPSFont); + if (m_PSFontList.empty() || m_PSFontList.back()->m_nGlyphs == 256) { + m_PSFontList.push_back(pdfium::MakeUnique()); + m_PSFontList.back()->m_nGlyphs = 0; CFX_ByteTextBuf buf; buf << "8 dict begin/FontType 3 def/FontMatrix[1 0 0 1 0 0]def\n" "/FontBBox[0 0 0 0]def/Encoding 256 array def 0 1 255{Encoding " @@ -573,12 +567,13 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, "/BuildChar{1 index/Encoding get exch get 1 index/BuildGlyph get " "exec}bind def\n" "currentdict end\n"; - buf << "/X" << m_PSFontList.GetSize() - 1 << " exch definefont pop\n"; + buf << "/X" << static_cast(m_PSFontList.size() - 1) + << " exch definefont pop\n"; m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); buf.Clear(); } - *ps_fontnum = m_PSFontList.GetSize() - 1; - CPSFont* pPSFont = m_PSFontList[*ps_fontnum]; + *ps_fontnum = m_PSFontList.size() - 1; + CPSFont* pPSFont = m_PSFontList[*ps_fontnum].get(); int glyphindex = pPSFont->m_nGlyphs; *ps_glyphindex = glyphindex; pPSFont->m_Glyphs[glyphindex].m_GlyphIndex = charpos.m_GlyphIndex; diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h index c70708a5a4..e941739f44 100644 --- a/core/fxge/win32/cfx_psrenderer.h +++ b/core/fxge/win32/cfx_psrenderer.h @@ -7,6 +7,9 @@ #ifndef CORE_FXGE_WIN32_CFX_PSRENDERER_H_ #define CORE_FXGE_WIN32_CFX_PSRENDERER_H_ +#include +#include + #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/cfx_graphstatedata.h" @@ -90,8 +93,8 @@ class CFX_PSRenderer { bool m_bColorSet; uint32_t m_LastColor; FX_RECT m_ClipBox; - CFX_ArrayTemplate m_PSFontList; - CFX_ArrayTemplate m_ClipBoxStack; + std::vector> m_PSFontList; + std::vector m_ClipBoxStack; bool m_bInited; }; -- cgit v1.2.3