Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include "core/fxcrt/include/fx_coordinates.h" | 11 #include "core/fxcrt/include/fx_coordinates.h" |
| 12 #include "core/fxcrt/include/fx_system.h" | 12 #include "core/fxcrt/include/fx_system.h" |
| 13 #include "xfa/fde/fde_brush.h" | |
| 14 #include "xfa/fde/fde_object.h" | 13 #include "xfa/fde/fde_object.h" |
| 15 #include "xfa/fde/fde_pen.h" | |
| 16 #include "xfa/fde/fde_renderdevice.h" | 14 #include "xfa/fde/fde_renderdevice.h" |
| 17 #include "xfa/fgas/crt/fgas_memory.h" | 15 #include "xfa/fgas/crt/fgas_memory.h" |
| 18 #include "xfa/fgas/crt/fgas_utils.h" | 16 #include "xfa/fgas/crt/fgas_utils.h" |
| 19 #include "xfa/fgas/layout/fgas_textbreak.h" | 17 #include "xfa/fgas/layout/fgas_textbreak.h" |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 struct FDE_TTOPIECE { | 21 struct FDE_TTOPIECE { |
| 24 public: | 22 public: |
| 25 int32_t iStartChar; | 23 int32_t iStartChar; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 void AppendPiece(const FDE_TTOPIECE& ttoPiece, | 136 void AppendPiece(const FDE_TTOPIECE& ttoPiece, |
| 139 FX_BOOL bNeedReload, | 137 FX_BOOL bNeedReload, |
| 140 FX_BOOL bEnd); | 138 FX_BOOL bEnd); |
| 141 void ReplaceWidthEllipsis(); | 139 void ReplaceWidthEllipsis(); |
| 142 void DoAlignment(const CFX_RectF& rect); | 140 void DoAlignment(const CFX_RectF& rect); |
| 143 void OnDraw(const CFX_RectF& rtClip); | 141 void OnDraw(const CFX_RectF& rtClip); |
| 144 int32_t GetDisplayPos(FDE_LPTTOPIECE pPiece); | 142 int32_t GetDisplayPos(FDE_LPTTOPIECE pPiece); |
| 145 int32_t GetCharRects(FDE_LPTTOPIECE pPiece); | 143 int32_t GetCharRects(FDE_LPTTOPIECE pPiece); |
| 146 | 144 |
| 147 void ToTextRun(const FDE_LPTTOPIECE pPiece, FX_TXTRUN& tr); | 145 void ToTextRun(const FDE_LPTTOPIECE pPiece, FX_TXTRUN& tr); |
| 148 void DrawLine(const FDE_LPTTOPIECE pPiece, IFDE_Pen*& pPen); | 146 void DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen); |
| 149 | 147 |
| 150 IFX_TxtBreak* m_pTxtBreak; | 148 IFX_TxtBreak* m_pTxtBreak; |
| 151 IFX_Font* m_pFont; | 149 IFX_Font* m_pFont; |
| 152 FX_FLOAT m_fFontSize; | 150 FX_FLOAT m_fFontSize; |
| 153 FX_FLOAT m_fLineSpace; | 151 FX_FLOAT m_fLineSpace; |
| 154 FX_FLOAT m_fLinePos; | 152 FX_FLOAT m_fLinePos; |
| 155 FX_FLOAT m_fTolerance; | 153 FX_FLOAT m_fTolerance; |
| 156 int32_t m_iAlignment; | 154 int32_t m_iAlignment; |
| 157 int32_t m_iTxtBkAlignment; | 155 int32_t m_iTxtBkAlignment; |
| 158 int32_t* m_pCharWidths; | 156 int32_t* m_pCharWidths; |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 } | 942 } |
| 945 } | 943 } |
| 946 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { | 944 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { |
| 947 if (m_pRenderDevice == NULL) { | 945 if (m_pRenderDevice == NULL) { |
| 948 return; | 946 return; |
| 949 } | 947 } |
| 950 int32_t iLines = m_ttoLines.GetSize(); | 948 int32_t iLines = m_ttoLines.GetSize(); |
| 951 if (iLines < 1) { | 949 if (iLines < 1) { |
| 952 return; | 950 return; |
| 953 } | 951 } |
| 954 IFDE_SolidBrush* pBrush = new CFDE_SolidBrush; | 952 CFDE_Brush* pBrush = new CFDE_Brush; |
| 955 pBrush->SetColor(m_TxtColor); | 953 pBrush->SetColor(m_TxtColor); |
| 956 IFDE_Pen* pPen = NULL; | 954 CFDE_Pen* pPen = NULL; |
| 957 FDE_HDEVICESTATE hDev = m_pRenderDevice->SaveState(); | 955 FDE_HDEVICESTATE hDev = m_pRenderDevice->SaveState(); |
| 958 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { | 956 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { |
| 959 m_pRenderDevice->SetClipRect(rtClip); | 957 m_pRenderDevice->SetClipRect(rtClip); |
| 960 } | 958 } |
| 961 for (int32_t i = 0; i < iLines; i++) { | 959 for (int32_t i = 0; i < iLines; i++) { |
| 962 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 960 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
| 963 int32_t iPieces = pLine->GetSize(); | 961 int32_t iPieces = pLine->GetSize(); |
| 964 for (int32_t j = 0; j < iPieces; j++) { | 962 for (int32_t j = 0; j < iPieces; j++) { |
| 965 FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); | 963 FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); |
| 966 if (pPiece == NULL) { | 964 if (pPiece == NULL) { |
| 967 continue; | 965 continue; |
| 968 } | 966 } |
| 969 int32_t iCount = GetDisplayPos(pPiece); | 967 int32_t iCount = GetDisplayPos(pPiece); |
| 970 if (iCount > 0) { | 968 if (iCount > 0) { |
| 971 m_pRenderDevice->DrawString(pBrush, m_pFont, m_pCharPos, iCount, | 969 m_pRenderDevice->DrawString(pBrush, m_pFont, m_pCharPos, iCount, |
| 972 m_fFontSize, &m_Matrix); | 970 m_fFontSize, &m_Matrix); |
| 973 } | 971 } |
| 974 DrawLine(pPiece, pPen); | 972 DrawLine(pPiece, pPen); |
| 975 } | 973 } |
| 976 } | 974 } |
| 977 m_pRenderDevice->RestoreState(hDev); | 975 m_pRenderDevice->RestoreState(hDev); |
| 978 if (pBrush) { | 976 if (pBrush) |
|
Tom Sepez
2016/04/12 20:03:34
nit: no need to test, just delete.
dsinclair
2016/04/12 20:08:32
Done.
| |
| 979 pBrush->Release(); | 977 delete pBrush; |
| 980 } | 978 if (pPen) |
| 981 if (pPen) { | 979 delete pPen; |
| 982 pPen->Release(); | |
| 983 } | |
| 984 } | 980 } |
| 985 int32_t CFDE_TextOut::GetDisplayPos(FDE_LPTTOPIECE pPiece) { | 981 int32_t CFDE_TextOut::GetDisplayPos(FDE_LPTTOPIECE pPiece) { |
| 986 FX_TXTRUN tr; | 982 FX_TXTRUN tr; |
| 987 ToTextRun(pPiece, tr); | 983 ToTextRun(pPiece, tr); |
| 988 ExpandBuffer(tr.iLength, 2); | 984 ExpandBuffer(tr.iLength, 2); |
| 989 return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); | 985 return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); |
| 990 } | 986 } |
| 991 int32_t CFDE_TextOut::GetCharRects(FDE_LPTTOPIECE pPiece) { | 987 int32_t CFDE_TextOut::GetCharRects(FDE_LPTTOPIECE pPiece) { |
| 992 FX_TXTRUN tr; | 988 FX_TXTRUN tr; |
| 993 ToTextRun(pPiece, tr); | 989 ToTextRun(pPiece, tr); |
| 994 m_rectArray.RemoveAll(); | 990 m_rectArray.RemoveAll(); |
| 995 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); | 991 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); |
| 996 } | 992 } |
| 997 void CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece, FX_TXTRUN& tr) { | 993 void CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece, FX_TXTRUN& tr) { |
| 998 tr.pAccess = NULL; | 994 tr.pAccess = NULL; |
| 999 tr.pIdentity = NULL; | 995 tr.pIdentity = NULL; |
| 1000 tr.pStr = (const FX_WCHAR*)m_wsText + pPiece->iStartChar; | 996 tr.pStr = (const FX_WCHAR*)m_wsText + pPiece->iStartChar; |
| 1001 tr.pWidths = m_pCharWidths + pPiece->iStartChar; | 997 tr.pWidths = m_pCharWidths + pPiece->iStartChar; |
| 1002 tr.iLength = pPiece->iChars; | 998 tr.iLength = pPiece->iChars; |
| 1003 tr.pFont = m_pFont; | 999 tr.pFont = m_pFont; |
| 1004 tr.fFontSize = m_fFontSize; | 1000 tr.fFontSize = m_fFontSize; |
| 1005 tr.dwStyles = m_dwTxtBkStyles; | 1001 tr.dwStyles = m_dwTxtBkStyles; |
| 1006 tr.iCharRotation = 0; | 1002 tr.iCharRotation = 0; |
| 1007 tr.dwCharStyles = pPiece->dwCharStyles; | 1003 tr.dwCharStyles = pPiece->dwCharStyles; |
| 1008 tr.wLineBreakChar = m_wParagraphBkChar; | 1004 tr.wLineBreakChar = m_wParagraphBkChar; |
| 1009 tr.pRect = &pPiece->rtPiece; | 1005 tr.pRect = &pPiece->rtPiece; |
| 1010 } | 1006 } |
| 1011 void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, IFDE_Pen*& pPen) { | 1007 void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen) { |
| 1012 FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); | 1008 FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); |
| 1013 FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); | 1009 FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); |
| 1014 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 1010 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
| 1015 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 1011 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 1016 if (!bUnderLine && !bStrikeOut && !bHotKey) { | 1012 if (!bUnderLine && !bStrikeOut && !bHotKey) { |
| 1017 return; | 1013 return; |
| 1018 } | 1014 } |
| 1019 if (pPen == NULL) { | 1015 if (pPen == NULL) { |
| 1020 pPen = new CFDE_Pen; | 1016 pPen = new CFDE_Pen; |
| 1021 pPen->SetColor(m_TxtColor); | 1017 pPen->SetColor(m_TxtColor); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 return NULL; | 1107 return NULL; |
| 1112 } | 1108 } |
| 1113 return m_pieces.GetPtrAt(index); | 1109 return m_pieces.GetPtrAt(index); |
| 1114 } | 1110 } |
| 1115 void CFDE_TTOLine::RemoveLast(int32_t iCount) { | 1111 void CFDE_TTOLine::RemoveLast(int32_t iCount) { |
| 1116 m_pieces.RemoveLast(iCount); | 1112 m_pieces.RemoveLast(iCount); |
| 1117 } | 1113 } |
| 1118 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { | 1114 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { |
| 1119 m_pieces.RemoveAll(bLeaveMemory); | 1115 m_pieces.RemoveAll(bLeaveMemory); |
| 1120 } | 1116 } |
| OLD | NEW |