| 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/cfde_path.h" | 13 #include "xfa/fde/cfde_path.h" |
| 14 #include "xfa/fde/fde_gedevice.h" | 14 #include "xfa/fde/fde_gedevice.h" |
| 15 #include "xfa/fde/fde_object.h" | 15 #include "xfa/fde/fde_object.h" |
| 16 #include "xfa/fgas/crt/fgas_memory.h" | 16 #include "xfa/fgas/crt/fgas_memory.h" |
| 17 #include "xfa/fgas/crt/fgas_utils.h" | 17 #include "xfa/fgas/crt/fgas_utils.h" |
| 18 #include "xfa/fgas/layout/fgas_textbreak.h" | 18 #include "xfa/fgas/layout/fgas_textbreak.h" |
| 19 | 19 |
| 20 CFDE_TextOut::CFDE_TextOut() | 20 CFDE_TextOut::CFDE_TextOut() |
| 21 : m_pFont(nullptr), | 21 : m_pTxtBreak(new CFX_TxtBreak(FX_TXTBREAKPOLICY_None)), |
| 22 m_pFont(nullptr), |
| 22 m_fFontSize(12.0f), | 23 m_fFontSize(12.0f), |
| 23 m_fLineSpace(m_fFontSize), | 24 m_fLineSpace(m_fFontSize), |
| 24 m_fLinePos(0.0f), | 25 m_fLinePos(0.0f), |
| 25 m_fTolerance(0.0f), | 26 m_fTolerance(0.0f), |
| 26 m_iAlignment(0), | 27 m_iAlignment(0), |
| 27 m_iTxtBkAlignment(0), | 28 m_iTxtBkAlignment(0), |
| 28 m_pCharWidths(nullptr), | |
| 29 m_iChars(0), | |
| 30 m_pEllCharWidths(nullptr), | |
| 31 m_iEllChars(0), | |
| 32 m_wParagraphBkChar(L'\n'), | 29 m_wParagraphBkChar(L'\n'), |
| 33 m_TxtColor(0xFF000000), | 30 m_TxtColor(0xFF000000), |
| 34 m_dwStyles(0), | 31 m_dwStyles(0), |
| 35 m_dwTxtBkStyles(0), | 32 m_dwTxtBkStyles(0), |
| 36 m_bElliChanged(FALSE), | 33 m_bElliChanged(FALSE), |
| 37 m_iEllipsisWidth(0), | 34 m_iEllipsisWidth(0), |
| 38 m_ttoLines(5), | 35 m_ttoLines(5), |
| 39 m_iCurLine(0), | 36 m_iCurLine(0), |
| 40 m_iCurPiece(0), | 37 m_iCurPiece(0), |
| 41 m_iTotalLines(0), | 38 m_iTotalLines(0) { |
| 42 m_pCharPos(nullptr), | |
| 43 m_iCharPosSize(0) { | |
| 44 m_pTxtBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); | |
| 45 m_Matrix.SetIdentity(); | 39 m_Matrix.SetIdentity(); |
| 46 m_rtClip.Reset(); | 40 m_rtClip.Reset(); |
| 47 m_rtLogicClip.Reset(); | 41 m_rtLogicClip.Reset(); |
| 48 } | 42 } |
| 43 |
| 49 CFDE_TextOut::~CFDE_TextOut() { | 44 CFDE_TextOut::~CFDE_TextOut() { |
| 50 delete m_pTxtBreak; | |
| 51 FX_Free(m_pCharWidths); | |
| 52 FX_Free(m_pEllCharWidths); | |
| 53 FX_Free(m_pCharPos); | |
| 54 m_ttoLines.RemoveAll(FALSE); | 45 m_ttoLines.RemoveAll(FALSE); |
| 55 } | 46 } |
| 47 |
| 56 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { | 48 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { |
| 57 ASSERT(pFont); | 49 ASSERT(pFont); |
| 58 m_pFont = pFont; | 50 m_pFont = pFont; |
| 59 m_pTxtBreak->SetFont(pFont); | 51 m_pTxtBreak->SetFont(pFont); |
| 60 } | 52 } |
| 53 |
| 61 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { | 54 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { |
| 62 ASSERT(fFontSize > 0); | 55 ASSERT(fFontSize > 0); |
| 63 m_fFontSize = fFontSize; | 56 m_fFontSize = fFontSize; |
| 64 m_pTxtBreak->SetFontSize(fFontSize); | 57 m_pTxtBreak->SetFontSize(fFontSize); |
| 65 } | 58 } |
| 59 |
| 66 void CFDE_TextOut::SetTextColor(FX_ARGB color) { | 60 void CFDE_TextOut::SetTextColor(FX_ARGB color) { |
| 67 m_TxtColor = color; | 61 m_TxtColor = color; |
| 68 } | 62 } |
| 63 |
| 69 void CFDE_TextOut::SetStyles(uint32_t dwStyles) { | 64 void CFDE_TextOut::SetStyles(uint32_t dwStyles) { |
| 70 m_dwStyles = dwStyles; | 65 m_dwStyles = dwStyles; |
| 71 m_dwTxtBkStyles = 0; | 66 m_dwTxtBkStyles = 0; |
| 72 if (dwStyles & FDE_TTOSTYLE_SingleLine) { | 67 if (dwStyles & FDE_TTOSTYLE_SingleLine) { |
| 73 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_SingleLine; | 68 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_SingleLine; |
| 74 } | 69 } |
| 75 if (dwStyles & FDE_TTOSTYLE_ExpandTab) { | 70 if (dwStyles & FDE_TTOSTYLE_ExpandTab) { |
| 76 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ExpandTab; | 71 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ExpandTab; |
| 77 } | 72 } |
| 78 if (dwStyles & FDE_TTOSTYLE_ArabicShapes) { | 73 if (dwStyles & FDE_TTOSTYLE_ArabicShapes) { |
| 79 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicShapes; | 74 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicShapes; |
| 80 } | 75 } |
| 81 if (dwStyles & FDE_TTOSTYLE_RTL) { | 76 if (dwStyles & FDE_TTOSTYLE_RTL) { |
| 82 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_RTLReadingOrder; | 77 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_RTLReadingOrder; |
| 83 } | 78 } |
| 84 if (dwStyles & FDE_TTOSTYLE_ArabicContext) { | 79 if (dwStyles & FDE_TTOSTYLE_ArabicContext) { |
| 85 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicContext; | 80 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicContext; |
| 86 } | 81 } |
| 87 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 82 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
| 88 m_dwTxtBkStyles |= | 83 m_dwTxtBkStyles |= |
| 89 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); | 84 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); |
| 90 } | 85 } |
| 91 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); | 86 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); |
| 92 } | 87 } |
| 88 |
| 93 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { | 89 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { |
| 94 ASSERT(fTabWidth > 1.0f); | 90 ASSERT(fTabWidth > 1.0f); |
| 95 m_pTxtBreak->SetTabWidth(fTabWidth, FALSE); | 91 m_pTxtBreak->SetTabWidth(fTabWidth, FALSE); |
| 96 } | 92 } |
| 93 |
| 97 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { | 94 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { |
| 98 m_bElliChanged = TRUE; | 95 m_bElliChanged = TRUE; |
| 99 m_wsEllipsis = wsEllipsis; | 96 m_wsEllipsis = wsEllipsis; |
| 100 } | 97 } |
| 98 |
| 101 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { | 99 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { |
| 102 m_wParagraphBkChar = wch; | 100 m_wParagraphBkChar = wch; |
| 103 m_pTxtBreak->SetParagraphBreakChar(wch); | 101 m_pTxtBreak->SetParagraphBreakChar(wch); |
| 104 } | 102 } |
| 103 |
| 105 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { | 104 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { |
| 106 m_iAlignment = iAlignment; | 105 m_iAlignment = iAlignment; |
| 107 switch (m_iAlignment) { | 106 switch (m_iAlignment) { |
| 108 case FDE_TTOALIGNMENT_TopCenter: | 107 case FDE_TTOALIGNMENT_TopCenter: |
| 109 case FDE_TTOALIGNMENT_Center: | 108 case FDE_TTOALIGNMENT_Center: |
| 110 case FDE_TTOALIGNMENT_BottomCenter: | 109 case FDE_TTOALIGNMENT_BottomCenter: |
| 111 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Center; | 110 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Center; |
| 112 break; | 111 break; |
| 113 case FDE_TTOALIGNMENT_TopRight: | 112 case FDE_TTOALIGNMENT_TopRight: |
| 114 case FDE_TTOALIGNMENT_CenterRight: | 113 case FDE_TTOALIGNMENT_CenterRight: |
| 115 case FDE_TTOALIGNMENT_BottomRight: | 114 case FDE_TTOALIGNMENT_BottomRight: |
| 116 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Right; | 115 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Right; |
| 117 break; | 116 break; |
| 118 default: | 117 default: |
| 119 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Left; | 118 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Left; |
| 120 break; | 119 break; |
| 121 } | 120 } |
| 122 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); | 121 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); |
| 123 } | 122 } |
| 123 |
| 124 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { | 124 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { |
| 125 ASSERT(fLineSpace > 1.0f); | 125 ASSERT(fLineSpace > 1.0f); |
| 126 m_fLineSpace = fLineSpace; | 126 m_fLineSpace = fLineSpace; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { | 129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { |
| 130 ASSERT(pDIB); | 130 ASSERT(pDIB); |
| 131 | 131 |
| 132 m_pRenderDevice.reset(); | 132 m_pRenderDevice.reset(); |
| 133 CFX_FxgeDevice* device = new CFX_FxgeDevice; | 133 CFX_FxgeDevice* device = new CFX_FxgeDevice; |
| 134 device->Attach(pDIB, false, nullptr, false); | 134 device->Attach(pDIB, false, nullptr, false); |
| 135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE)); | 135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { | 138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { |
| 139 ASSERT(pDevice); | 139 ASSERT(pDevice); |
| 140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE)); | 140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { | 143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { |
| 144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, | 144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, |
| 145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); | 145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); |
| 146 } | 146 } |
| 147 |
| 147 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { | 148 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { |
| 148 m_rtClip = rtClip; | 149 m_rtClip = rtClip; |
| 149 } | 150 } |
| 151 |
| 150 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { | 152 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { |
| 151 m_rtLogicClip = rtClip; | 153 m_rtLogicClip = rtClip; |
| 152 } | 154 } |
| 155 |
| 153 void CFDE_TextOut::SetMatrix(const CFX_Matrix& matrix) { | 156 void CFDE_TextOut::SetMatrix(const CFX_Matrix& matrix) { |
| 154 m_Matrix = matrix; | 157 m_Matrix = matrix; |
| 155 } | 158 } |
| 159 |
| 156 void CFDE_TextOut::SetLineBreakTolerance(FX_FLOAT fTolerance) { | 160 void CFDE_TextOut::SetLineBreakTolerance(FX_FLOAT fTolerance) { |
| 157 m_fTolerance = fTolerance; | 161 m_fTolerance = fTolerance; |
| 158 m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); | 162 m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); |
| 159 } | 163 } |
| 164 |
| 160 int32_t CFDE_TextOut::GetTotalLines() { | 165 int32_t CFDE_TextOut::GetTotalLines() { |
| 161 return m_iTotalLines; | 166 return m_iTotalLines; |
| 162 } | 167 } |
| 168 |
| 163 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 169 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
| 164 int32_t iLength, | 170 int32_t iLength, |
| 165 CFX_Size& size) { | 171 CFX_Size& size) { |
| 166 CFX_RectF rtText; | 172 CFX_RectF rtText; |
| 167 rtText.Set(0.0f, 0.0f, (FX_FLOAT)size.x, (FX_FLOAT)size.y); | 173 rtText.Set(0.0f, 0.0f, (FX_FLOAT)size.x, (FX_FLOAT)size.y); |
| 168 CalcSize(pwsStr, iLength, rtText); | 174 CalcSize(pwsStr, iLength, rtText); |
| 169 size.x = (int32_t)rtText.Width(); | 175 size.x = (int32_t)rtText.Width(); |
| 170 size.y = (int32_t)rtText.Height(); | 176 size.y = (int32_t)rtText.Height(); |
| 171 } | 177 } |
| 178 |
| 172 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 179 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
| 173 int32_t iLength, | 180 int32_t iLength, |
| 174 CFX_SizeF& size) { | 181 CFX_SizeF& size) { |
| 175 CFX_RectF rtText; | 182 CFX_RectF rtText; |
| 176 rtText.Set(0.0f, 0.0f, size.x, size.y); | 183 rtText.Set(0.0f, 0.0f, size.x, size.y); |
| 177 CalcSize(pwsStr, iLength, rtText); | 184 CalcSize(pwsStr, iLength, rtText); |
| 178 size.x = rtText.Width(); | 185 size.x = rtText.Width(); |
| 179 size.y = rtText.Height(); | 186 size.y = rtText.Height(); |
| 180 } | 187 } |
| 188 |
| 181 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 189 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
| 182 int32_t iLength, | 190 int32_t iLength, |
| 183 CFX_Rect& rect) { | 191 CFX_Rect& rect) { |
| 184 CFX_RectF rtText; | 192 CFX_RectF rtText; |
| 185 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.Width(), | 193 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.Width(), |
| 186 (FX_FLOAT)rect.Height()); | 194 (FX_FLOAT)rect.Height()); |
| 187 CalcSize(pwsStr, iLength, rtText); | 195 CalcSize(pwsStr, iLength, rtText); |
| 188 rect.Set((int32_t)rtText.left, (int32_t)rtText.top, (int32_t)rtText.Width(), | 196 rect.Set((int32_t)rtText.left, (int32_t)rtText.top, (int32_t)rtText.Width(), |
| 189 (int32_t)rtText.Height()); | 197 (int32_t)rtText.Height()); |
| 190 } | 198 } |
| 199 |
| 191 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 200 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
| 192 int32_t iLength, | 201 int32_t iLength, |
| 193 CFX_RectF& rect) { | 202 CFX_RectF& rect) { |
| 194 if (!pwsStr || iLength < 1) { | 203 if (!pwsStr || iLength < 1) { |
| 195 rect.width = 0.0f; | 204 rect.width = 0.0f; |
| 196 rect.height = 0.0f; | 205 rect.height = 0.0f; |
| 197 } else { | 206 } else { |
| 198 CFX_Matrix rm; | 207 CFX_Matrix rm; |
| 199 rm.SetReverse(m_Matrix); | 208 rm.SetReverse(m_Matrix); |
| 200 rm.TransformRect(rect); | 209 rm.TransformRect(rect); |
| 201 CalcTextSize(pwsStr, iLength, rect); | 210 CalcTextSize(pwsStr, iLength, rect); |
| 202 m_Matrix.TransformRect(rect); | 211 m_Matrix.TransformRect(rect); |
| 203 } | 212 } |
| 204 } | 213 } |
| 214 |
| 205 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, | 215 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, |
| 206 int32_t iLength, | 216 int32_t iLength, |
| 207 CFX_SizeF& size) { | 217 CFX_SizeF& size) { |
| 208 CFX_RectF rtText; | 218 CFX_RectF rtText; |
| 209 rtText.Set(0.0f, 0.0f, size.x, size.y); | 219 rtText.Set(0.0f, 0.0f, size.x, size.y); |
| 210 CalcLogicSize(pwsStr, iLength, rtText); | 220 CalcLogicSize(pwsStr, iLength, rtText); |
| 211 size.x = rtText.Width(); | 221 size.x = rtText.Width(); |
| 212 size.y = rtText.Height(); | 222 size.y = rtText.Height(); |
| 213 } | 223 } |
| 224 |
| 214 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, | 225 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, |
| 215 int32_t iLength, | 226 int32_t iLength, |
| 216 CFX_RectF& rect) { | 227 CFX_RectF& rect) { |
| 217 if (!pwsStr || iLength < 1) { | 228 if (!pwsStr || iLength < 1) { |
| 218 rect.width = 0.0f; | 229 rect.width = 0.0f; |
| 219 rect.height = 0.0f; | 230 rect.height = 0.0f; |
| 220 } else { | 231 } else { |
| 221 CalcTextSize(pwsStr, iLength, rect); | 232 CalcTextSize(pwsStr, iLength, rect); |
| 222 } | 233 } |
| 223 } | 234 } |
| 235 |
| 224 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, | 236 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, |
| 225 int32_t iLength, | 237 int32_t iLength, |
| 226 CFX_RectF& rect) { | 238 CFX_RectF& rect) { |
| 227 ASSERT(m_pFont && m_fFontSize >= 1.0f); | 239 ASSERT(m_pFont && m_fFontSize >= 1.0f); |
| 228 SetLineWidth(rect); | 240 SetLineWidth(rect); |
| 229 m_iTotalLines = 0; | 241 m_iTotalLines = 0; |
| 230 const FX_WCHAR* pStr = pwsStr; | 242 const FX_WCHAR* pStr = pwsStr; |
| 231 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 243 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
| 232 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 244 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 233 FX_FLOAT fWidth = 0.0f; | 245 FX_FLOAT fWidth = 0.0f; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } else { | 288 } else { |
| 277 rect.left += fStartPos; | 289 rect.left += fStartPos; |
| 278 rect.top += fInc; | 290 rect.top += fInc; |
| 279 rect.width = std::min(fWidth, rect.Width()); | 291 rect.width = std::min(fWidth, rect.Width()); |
| 280 rect.height = fHeight; | 292 rect.height = fHeight; |
| 281 if (m_dwStyles & FDE_TTOSTYLE_LastLineHeight) { | 293 if (m_dwStyles & FDE_TTOSTYLE_LastLineHeight) { |
| 282 rect.height -= m_fLineSpace - m_fFontSize; | 294 rect.height -= m_fLineSpace - m_fFontSize; |
| 283 } | 295 } |
| 284 } | 296 } |
| 285 } | 297 } |
| 298 |
| 286 void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { | 299 void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { |
| 287 if ((m_dwStyles & FDE_TTOSTYLE_SingleLine) == 0) { | 300 if ((m_dwStyles & FDE_TTOSTYLE_SingleLine) == 0) { |
| 288 FX_FLOAT fLineWidth = 0.0f; | 301 FX_FLOAT fLineWidth = 0.0f; |
| 289 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 302 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
| 290 if (rect.Height() < 1.0f) { | 303 if (rect.Height() < 1.0f) { |
| 291 rect.height = m_fFontSize * 1000.0f; | 304 rect.height = m_fFontSize * 1000.0f; |
| 292 } | 305 } |
| 293 fLineWidth = rect.Height(); | 306 fLineWidth = rect.Height(); |
| 294 } else { | 307 } else { |
| 295 if (rect.Width() < 1.0f) { | 308 if (rect.Width() < 1.0f) { |
| 296 rect.width = m_fFontSize * 1000.0f; | 309 rect.width = m_fFontSize * 1000.0f; |
| 297 } | 310 } |
| 298 fLineWidth = rect.Width(); | 311 fLineWidth = rect.Width(); |
| 299 } | 312 } |
| 300 m_pTxtBreak->SetLineWidth(fLineWidth); | 313 m_pTxtBreak->SetLineWidth(fLineWidth); |
| 301 } | 314 } |
| 302 } | 315 } |
| 316 |
| 303 FX_BOOL CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, | 317 FX_BOOL CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, |
| 304 FX_FLOAT& fStartPos, | 318 FX_FLOAT& fStartPos, |
| 305 FX_FLOAT& fWidth, | 319 FX_FLOAT& fWidth, |
| 306 FX_FLOAT& fHeight) { | 320 FX_FLOAT& fHeight) { |
| 307 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { | 321 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { |
| 308 return FALSE; | 322 return FALSE; |
| 309 } | 323 } |
| 310 FX_FLOAT fLineStep = | 324 FX_FLOAT fLineStep = |
| 311 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 325 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
| 312 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 326 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 323 } | 337 } |
| 324 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { | 338 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { |
| 325 fWidth += fLineWidth; | 339 fWidth += fLineWidth; |
| 326 } else { | 340 } else { |
| 327 fWidth = std::max(fWidth, fLineWidth); | 341 fWidth = std::max(fWidth, fLineWidth); |
| 328 fHeight += fLineStep; | 342 fHeight += fLineStep; |
| 329 } | 343 } |
| 330 m_iTotalLines++; | 344 m_iTotalLines++; |
| 331 return TRUE; | 345 return TRUE; |
| 332 } | 346 } |
| 347 |
| 333 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 348 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
| 334 int32_t iLength, | 349 int32_t iLength, |
| 335 int32_t x, | 350 int32_t x, |
| 336 int32_t y) { | 351 int32_t y) { |
| 337 CFX_RectF rtText; | 352 CFX_RectF rtText; |
| 338 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, | 353 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, |
| 339 m_fFontSize * 1000.0f); | 354 m_fFontSize * 1000.0f); |
| 340 DrawText(pwsStr, iLength, rtText); | 355 DrawText(pwsStr, iLength, rtText); |
| 341 } | 356 } |
| 357 |
| 342 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 358 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
| 343 int32_t iLength, | 359 int32_t iLength, |
| 344 FX_FLOAT x, | 360 FX_FLOAT x, |
| 345 FX_FLOAT y) { | 361 FX_FLOAT y) { |
| 346 CFX_RectF rtText; | 362 CFX_RectF rtText; |
| 347 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); | 363 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); |
| 348 DrawText(pwsStr, iLength, rtText); | 364 DrawText(pwsStr, iLength, rtText); |
| 349 } | 365 } |
| 366 |
| 350 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 367 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
| 351 int32_t iLength, | 368 int32_t iLength, |
| 352 const CFX_Rect& rect) { | 369 const CFX_Rect& rect) { |
| 353 CFX_RectF rtText; | 370 CFX_RectF rtText; |
| 354 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.width, | 371 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.width, |
| 355 (FX_FLOAT)rect.height); | 372 (FX_FLOAT)rect.height); |
| 356 DrawText(pwsStr, iLength, rtText); | 373 DrawText(pwsStr, iLength, rtText); |
| 357 } | 374 } |
| 375 |
| 358 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 376 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
| 359 int32_t iLength, | 377 int32_t iLength, |
| 360 const CFX_RectF& rect) { | 378 const CFX_RectF& rect) { |
| 361 CFX_RectF rtText; | 379 CFX_RectF rtText; |
| 362 rtText.Set(rect.left, rect.top, rect.width, rect.height); | 380 rtText.Set(rect.left, rect.top, rect.width, rect.height); |
| 363 CFX_Matrix rm; | 381 CFX_Matrix rm; |
| 364 rm.SetReverse(m_Matrix); | 382 rm.SetReverse(m_Matrix); |
| 365 rm.TransformRect(rtText); | 383 rm.TransformRect(rtText); |
| 366 DrawText(pwsStr, iLength, rtText, m_rtClip); | 384 DrawText(pwsStr, iLength, rtText, m_rtClip); |
| 367 } | 385 } |
| 386 |
| 368 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, | 387 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, |
| 369 int32_t iLength, | 388 int32_t iLength, |
| 370 FX_FLOAT x, | 389 FX_FLOAT x, |
| 371 FX_FLOAT y) { | 390 FX_FLOAT y) { |
| 372 CFX_RectF rtText; | 391 CFX_RectF rtText; |
| 373 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); | 392 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); |
| 374 DrawLogicText(pwsStr, iLength, rtText); | 393 DrawLogicText(pwsStr, iLength, rtText); |
| 375 } | 394 } |
| 395 |
| 376 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, | 396 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, |
| 377 int32_t iLength, | 397 int32_t iLength, |
| 378 const CFX_RectF& rect) { | 398 const CFX_RectF& rect) { |
| 379 CFX_RectF rtClip; | 399 CFX_RectF rtClip; |
| 380 rtClip.Set(m_rtLogicClip.left, m_rtLogicClip.top, m_rtLogicClip.width, | 400 rtClip.Set(m_rtLogicClip.left, m_rtLogicClip.top, m_rtLogicClip.width, |
| 381 m_rtLogicClip.height); | 401 m_rtLogicClip.height); |
| 382 m_Matrix.TransformRect(rtClip); | 402 m_Matrix.TransformRect(rtClip); |
| 383 DrawText(pwsStr, iLength, rect, rtClip); | 403 DrawText(pwsStr, iLength, rect, rtClip); |
| 384 } | 404 } |
| 405 |
| 385 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 406 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
| 386 int32_t iLength, | 407 int32_t iLength, |
| 387 const CFX_RectF& rect, | 408 const CFX_RectF& rect, |
| 388 const CFX_RectF& rtClip) { | 409 const CFX_RectF& rtClip) { |
| 389 ASSERT(m_pFont && m_fFontSize >= 1.0f); | 410 ASSERT(m_pFont && m_fFontSize >= 1.0f); |
| 390 if (!pwsStr || iLength < 1) | 411 if (!pwsStr || iLength < 1) |
| 391 return; | 412 return; |
| 392 | 413 |
| 393 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { | 414 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { |
| 394 return; | 415 return; |
| 395 } | 416 } |
| 396 FX_FLOAT fLineWidth = rect.width; | 417 FX_FLOAT fLineWidth = rect.width; |
| 397 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 418 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
| 398 fLineWidth = rect.height; | 419 fLineWidth = rect.height; |
| 399 } | 420 } |
| 400 m_pTxtBreak->SetLineWidth(fLineWidth); | 421 m_pTxtBreak->SetLineWidth(fLineWidth); |
| 401 m_ttoLines.RemoveAll(TRUE); | 422 m_ttoLines.RemoveAll(TRUE); |
| 402 m_wsText.clear(); | 423 m_wsText.clear(); |
| 403 LoadText(pwsStr, iLength, rect); | 424 LoadText(pwsStr, iLength, rect); |
| 404 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { | 425 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { |
| 405 ReplaceWidthEllipsis(); | 426 ReplaceWidthEllipsis(); |
| 406 } | 427 } |
| 407 Reload(rect); | 428 Reload(rect); |
| 408 DoAlignment(rect); | 429 DoAlignment(rect); |
| 409 OnDraw(rtClip); | 430 OnDraw(rtClip); |
| 410 } | 431 } |
| 432 |
| 411 void CFDE_TextOut::ExpandBuffer(int32_t iSize, int32_t iType) { | 433 void CFDE_TextOut::ExpandBuffer(int32_t iSize, int32_t iType) { |
| 434 ASSERT(iSize >= 0); |
| 435 size_t size = iSize; |
| 412 switch (iType) { | 436 switch (iType) { |
| 413 case 0: | 437 case 0: |
| 414 if (!m_pCharWidths) { | 438 if (m_CharWidths.size() < size) |
| 415 m_pCharWidths = FX_Alloc(int32_t, iSize); | 439 m_CharWidths.resize(size, 0); |
| 416 m_iChars = iSize; | |
| 417 } else if (m_iChars < iSize) { | |
| 418 m_pCharWidths = FX_Realloc(int32_t, m_pCharWidths, iSize); | |
| 419 m_iChars = iSize; | |
| 420 } | |
| 421 FXSYS_memset(m_pCharWidths, 0, iSize * sizeof(int32_t)); | |
| 422 break; | 440 break; |
| 423 case 1: | 441 case 1: |
| 424 if (!m_pEllCharWidths) { | 442 if (m_EllCharWidths.size() < size) |
| 425 m_pEllCharWidths = FX_Alloc(int32_t, iSize); | 443 m_EllCharWidths.resize(size, 0); |
| 426 m_iEllChars = iSize; | |
| 427 } else if (m_iEllChars < iSize) { | |
| 428 m_pEllCharWidths = FX_Realloc(int32_t, m_pEllCharWidths, iSize); | |
| 429 m_iEllChars = iSize; | |
| 430 } | |
| 431 FXSYS_memset(m_pEllCharWidths, 0, iSize * sizeof(int32_t)); | |
| 432 break; | 444 break; |
| 433 case 2: | 445 case 2: |
| 434 if (!m_pCharPos) { | 446 if (m_CharPos.size() < size) |
| 435 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iSize); | 447 m_CharPos.resize(size, FXTEXT_CHARPOS()); |
| 436 m_iCharPosSize = iSize; | |
| 437 } else if (m_iCharPosSize < iSize) { | |
| 438 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iSize); | |
| 439 m_iCharPosSize = iSize; | |
| 440 } | |
| 441 break; | 448 break; |
| 442 } | 449 } |
| 443 } | 450 } |
| 451 |
| 444 void CFDE_TextOut::LoadEllipsis() { | 452 void CFDE_TextOut::LoadEllipsis() { |
| 445 if (!m_bElliChanged) { | 453 if (!m_bElliChanged) { |
| 446 return; | 454 return; |
| 447 } | 455 } |
| 448 m_bElliChanged = FALSE; | 456 m_bElliChanged = FALSE; |
| 449 m_iEllipsisWidth = 0; | 457 m_iEllipsisWidth = 0; |
| 450 int32_t iLength = m_wsEllipsis.GetLength(); | 458 int32_t iLength = m_wsEllipsis.GetLength(); |
| 451 if (iLength < 1) { | 459 if (iLength < 1) { |
| 452 return; | 460 return; |
| 453 } | 461 } |
| 454 ExpandBuffer(iLength, 1); | 462 ExpandBuffer(iLength, 1); |
| 455 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); | 463 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); |
| 456 int32_t* pCharWidths = m_pEllCharWidths; | |
| 457 uint32_t dwBreakStatus; | 464 uint32_t dwBreakStatus; |
| 458 FX_WCHAR wch; | 465 FX_WCHAR wch; |
| 459 while (iLength-- > 0) { | 466 while (iLength-- > 0) { |
| 460 wch = *pStr++; | 467 wch = *pStr++; |
| 461 dwBreakStatus = m_pTxtBreak->AppendChar(wch); | 468 dwBreakStatus = m_pTxtBreak->AppendChar(wch); |
| 462 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 469 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) |
| 463 RetrieveEllPieces(pCharWidths); | 470 RetrieveEllPieces(&m_EllCharWidths); |
| 464 } | |
| 465 } | 471 } |
| 466 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 472 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
| 467 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 473 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) |
| 468 RetrieveEllPieces(pCharWidths); | 474 RetrieveEllPieces(&m_EllCharWidths); |
| 469 } | |
| 470 m_pTxtBreak->Reset(); | 475 m_pTxtBreak->Reset(); |
| 471 } | 476 } |
| 472 void CFDE_TextOut::RetrieveEllPieces(int32_t*& pCharWidths) { | 477 |
| 478 void CFDE_TextOut::RetrieveEllPieces(std::vector<int32_t>* pCharWidths) { |
| 473 int32_t iCount = m_pTxtBreak->CountBreakPieces(); | 479 int32_t iCount = m_pTxtBreak->CountBreakPieces(); |
| 474 CFX_Char* pTC; | 480 int32_t iCharIndex = 0; |
| 475 for (int32_t i = 0; i < iCount; i++) { | 481 for (int32_t i = 0; i < iCount; i++) { |
| 476 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); | 482 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); |
| 477 int32_t iPieceChars = pPiece->GetLength(); | 483 int32_t iPieceChars = pPiece->GetLength(); |
| 478 for (int32_t j = 0; j < iPieceChars; j++) { | 484 for (int32_t j = 0; j < iPieceChars; j++) { |
| 479 pTC = pPiece->GetCharPtr(j); | 485 CFX_Char* pTC = pPiece->GetCharPtr(j); |
| 480 if (pTC->m_iCharWidth <= 0) { | 486 (*pCharWidths)[iCharIndex] = std::max(pTC->m_iCharWidth, 0); |
| 481 *pCharWidths = 0; | 487 m_iEllipsisWidth += (*pCharWidths)[iCharIndex]; |
| 482 } else { | 488 iCharIndex++; |
| 483 *pCharWidths = pTC->m_iCharWidth; | |
| 484 } | |
| 485 m_iEllipsisWidth += *pCharWidths; | |
| 486 pCharWidths++; | |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 m_pTxtBreak->ClearBreakPieces(); | 491 m_pTxtBreak->ClearBreakPieces(); |
| 490 } | 492 } |
| 493 |
| 491 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, | 494 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, |
| 492 int32_t iLength, | 495 int32_t iLength, |
| 493 const CFX_RectF& rect) { | 496 const CFX_RectF& rect) { |
| 494 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); | 497 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); |
| 495 int32_t iTxtLength = iLength; | 498 int32_t iTxtLength = iLength; |
| 496 ExpandBuffer(iTxtLength, 0); | 499 ExpandBuffer(iTxtLength, 0); |
| 497 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 500 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
| 498 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 501 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 499 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 502 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
| 500 FX_FLOAT fLineStep = | 503 FX_FLOAT fLineStep = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 547 } |
| 545 } | 548 } |
| 546 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 549 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
| 547 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { | 550 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { |
| 548 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); | 551 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); |
| 549 } | 552 } |
| 550 m_pTxtBreak->ClearBreakPieces(); | 553 m_pTxtBreak->ClearBreakPieces(); |
| 551 m_pTxtBreak->Reset(); | 554 m_pTxtBreak->Reset(); |
| 552 m_wsText.ReleaseBuffer(iLength); | 555 m_wsText.ReleaseBuffer(iLength); |
| 553 } | 556 } |
| 557 |
| 554 FX_BOOL CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, | 558 FX_BOOL CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, |
| 555 int32_t& iStartChar, | 559 int32_t& iStartChar, |
| 556 int32_t& iPieceWidths, | 560 int32_t& iPieceWidths, |
| 557 FX_BOOL bReload, | 561 FX_BOOL bReload, |
| 558 const CFX_RectF& rect) { | 562 const CFX_RectF& rect) { |
| 559 FX_BOOL bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); | 563 FX_BOOL bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); |
| 560 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 564 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
| 561 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 565 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 562 FX_FLOAT fLineStep = | 566 FX_FLOAT fLineStep = |
| 563 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 567 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 578 for (; j < iPieceChars; j++) { | 582 for (; j < iPieceChars; j++) { |
| 579 pTC = pPiece->GetCharPtr(j); | 583 pTC = pPiece->GetCharPtr(j); |
| 580 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; | 584 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; |
| 581 if (bSingleLine || !bLineWrap) { | 585 if (bSingleLine || !bLineWrap) { |
| 582 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { | 586 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { |
| 583 bNeedReload = TRUE; | 587 bNeedReload = TRUE; |
| 584 break; | 588 break; |
| 585 } | 589 } |
| 586 } | 590 } |
| 587 iWidth += iCurCharWidth; | 591 iWidth += iCurCharWidth; |
| 588 m_pCharWidths[iChar++] = iCurCharWidth; | 592 m_CharWidths[iChar++] = iCurCharWidth; |
| 589 } | 593 } |
| 590 if (j == 0 && !bReload) { | 594 if (j == 0 && !bReload) { |
| 591 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 595 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
| 592 pLine->m_bNewReload = TRUE; | 596 pLine->m_bNewReload = TRUE; |
| 593 } else if (j > 0) { | 597 } else if (j > 0) { |
| 594 CFX_RectF rtPiece; | 598 CFX_RectF rtPiece; |
| 595 if (bVertical) { | 599 if (bVertical) { |
| 596 rtPiece.left = m_fLinePos; | 600 rtPiece.left = m_fLinePos; |
| 597 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | 601 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; |
| 598 rtPiece.width = fLineStep; | 602 rtPiece.width = fLineStep; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 614 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); | 618 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); |
| 615 } | 619 } |
| 616 iStartChar += iPieceChars; | 620 iStartChar += iPieceChars; |
| 617 iPieceWidths += iWidth; | 621 iPieceWidths += iWidth; |
| 618 } | 622 } |
| 619 m_pTxtBreak->ClearBreakPieces(); | 623 m_pTxtBreak->ClearBreakPieces(); |
| 620 FX_BOOL bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || | 624 FX_BOOL bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || |
| 621 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; | 625 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; |
| 622 return bRet; | 626 return bRet; |
| 623 } | 627 } |
| 628 |
| 624 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, | 629 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, |
| 625 FX_BOOL bNeedReload, | 630 FX_BOOL bNeedReload, |
| 626 FX_BOOL bEnd) { | 631 FX_BOOL bEnd) { |
| 627 if (m_iCurLine >= m_ttoLines.GetSize()) { | 632 if (m_iCurLine >= m_ttoLines.GetSize()) { |
| 628 CFDE_TTOLine ttoLine; | 633 CFDE_TTOLine ttoLine; |
| 629 ttoLine.m_bNewReload = bNeedReload; | 634 ttoLine.m_bNewReload = bNeedReload; |
| 630 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); | 635 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); |
| 631 m_iCurLine = m_ttoLines.Add(ttoLine); | 636 m_iCurLine = m_ttoLines.Add(ttoLine); |
| 632 } else { | 637 } else { |
| 633 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 638 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
| 634 pLine->m_bNewReload = bNeedReload; | 639 pLine->m_bNewReload = bNeedReload; |
| 635 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); | 640 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); |
| 636 if (bEnd) { | 641 if (bEnd) { |
| 637 int32_t iPieces = pLine->GetSize(); | 642 int32_t iPieces = pLine->GetSize(); |
| 638 if (m_iCurPiece < iPieces) { | 643 if (m_iCurPiece < iPieces) { |
| 639 pLine->RemoveLast(iPieces - m_iCurPiece - 1); | 644 pLine->RemoveLast(iPieces - m_iCurPiece - 1); |
| 640 } | 645 } |
| 641 } | 646 } |
| 642 } | 647 } |
| 643 if (!bEnd && bNeedReload) { | 648 if (!bEnd && bNeedReload) { |
| 644 m_iCurPiece = 0; | 649 m_iCurPiece = 0; |
| 645 } | 650 } |
| 646 } | 651 } |
| 652 |
| 647 void CFDE_TextOut::ReplaceWidthEllipsis() { | 653 void CFDE_TextOut::ReplaceWidthEllipsis() { |
| 648 LoadEllipsis(); | 654 LoadEllipsis(); |
| 649 int32_t iLength = m_wsEllipsis.GetLength(); | 655 int32_t iLength = m_wsEllipsis.GetLength(); |
| 650 if (iLength < 1) { | 656 if (iLength < 1) { |
| 651 return; | 657 return; |
| 652 } | 658 } |
| 653 int32_t iLines = m_ttoLines.GetSize(); | 659 int32_t iLines = m_ttoLines.GetSize(); |
| 654 for (int32_t i = 0; i < iLines; i++) { | 660 for (int32_t i = 0; i < iLines; i++) { |
| 655 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 661 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
| 656 if (!pLine->m_bNewReload) { | 662 if (!pLine->m_bNewReload) { |
| 657 continue; | 663 continue; |
| 658 } | 664 } |
| 659 int32_t iEllipsisCharIndex = iLength - 1; | 665 int32_t iEllipsisCharIndex = iLength - 1; |
| 660 int32_t iCharWidth = 0; | 666 int32_t iCharWidth = 0; |
| 661 int32_t iCharCount = 0; | 667 int32_t iCharCount = 0; |
| 662 int32_t iPiece = pLine->GetSize(); | 668 int32_t iPiece = pLine->GetSize(); |
| 663 while (iPiece-- > 0) { | 669 while (iPiece-- > 0) { |
| 664 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); | 670 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); |
| 665 if (!pPiece) | 671 if (!pPiece) |
| 666 break; | 672 break; |
| 667 | 673 |
| 668 for (int32_t j = pPiece->iChars - 1; j >= 0; j--) { | 674 for (int32_t j = pPiece->iChars - 1; j >= 0; j--) { |
| 669 if (iEllipsisCharIndex < 0) { | 675 if (iEllipsisCharIndex < 0) { |
| 670 break; | 676 break; |
| 671 } | 677 } |
| 672 int32_t index = pPiece->iStartChar + j; | 678 int32_t index = pPiece->iStartChar + j; |
| 673 iCharWidth += m_pCharWidths[index]; | 679 iCharWidth += m_CharWidths[index]; |
| 674 iCharCount++; | 680 iCharCount++; |
| 675 if (iCharCount <= iLength) { | 681 if (iCharCount <= iLength) { |
| 676 m_wsText.SetAt(index, m_wsEllipsis.GetAt(iEllipsisCharIndex)); | 682 m_wsText.SetAt(index, m_wsEllipsis.GetAt(iEllipsisCharIndex)); |
| 677 m_pCharWidths[index] = m_pEllCharWidths[iEllipsisCharIndex]; | 683 m_CharWidths[index] = m_EllCharWidths[iEllipsisCharIndex]; |
| 678 } else if (iCharWidth <= m_iEllipsisWidth) { | 684 } else if (iCharWidth <= m_iEllipsisWidth) { |
| 679 m_wsText.SetAt(index, 0); | 685 m_wsText.SetAt(index, 0); |
| 680 m_pCharWidths[index] = 0; | 686 m_CharWidths[index] = 0; |
| 681 } | 687 } |
| 682 iEllipsisCharIndex--; | 688 iEllipsisCharIndex--; |
| 683 } | 689 } |
| 684 if (iEllipsisCharIndex < 0) { | 690 if (iEllipsisCharIndex < 0) { |
| 685 break; | 691 break; |
| 686 } | 692 } |
| 687 } | 693 } |
| 688 } | 694 } |
| 689 } | 695 } |
| 696 |
| 690 void CFDE_TextOut::Reload(const CFX_RectF& rect) { | 697 void CFDE_TextOut::Reload(const CFX_RectF& rect) { |
| 691 int32_t iCount = m_ttoLines.GetSize(); | 698 int32_t iCount = m_ttoLines.GetSize(); |
| 692 for (int32_t i = 0; i < iCount; i++) { | 699 for (int32_t i = 0; i < iCount; i++) { |
| 693 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 700 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
| 694 if (!pLine || !pLine->m_bNewReload) | 701 if (!pLine || !pLine->m_bNewReload) |
| 695 continue; | 702 continue; |
| 696 | 703 |
| 697 m_iCurLine = i; | 704 m_iCurLine = i; |
| 698 m_iCurPiece = 0; | 705 m_iCurPiece = 0; |
| 699 ReloadLinePiece(pLine, rect); | 706 ReloadLinePiece(pLine, rect); |
| 700 } | 707 } |
| 701 } | 708 } |
| 709 |
| 702 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { | 710 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { |
| 703 const FX_WCHAR* pwsStr = m_wsText.c_str(); | 711 const FX_WCHAR* pwsStr = m_wsText.c_str(); |
| 704 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 712 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 705 int32_t iPieceWidths = 0; | 713 int32_t iPieceWidths = 0; |
| 706 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); | 714 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); |
| 707 int32_t iStartChar = pPiece->iStartChar; | 715 int32_t iStartChar = pPiece->iStartChar; |
| 708 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; | 716 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; |
| 709 int32_t iPieceCount = pLine->GetSize(); | 717 int32_t iPieceCount = pLine->GetSize(); |
| 710 int32_t iPieceIndex = 0; | 718 int32_t iPieceIndex = 0; |
| 711 uint32_t dwBreakStatus = 0; | 719 uint32_t dwBreakStatus = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 723 } | 731 } |
| 724 iPieceIndex++; | 732 iPieceIndex++; |
| 725 pPiece = pLine->GetPtrAt(iPieceIndex); | 733 pPiece = pLine->GetPtrAt(iPieceIndex); |
| 726 } | 734 } |
| 727 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 735 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
| 728 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 736 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { |
| 729 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); | 737 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); |
| 730 } | 738 } |
| 731 m_pTxtBreak->Reset(); | 739 m_pTxtBreak->Reset(); |
| 732 } | 740 } |
| 741 |
| 733 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { | 742 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { |
| 734 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 743 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
| 735 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); | 744 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); |
| 736 int32_t iLines = m_ttoLines.GetSize(); | 745 int32_t iLines = m_ttoLines.GetSize(); |
| 737 if (iLines < 1) | 746 if (iLines < 1) |
| 738 return; | 747 return; |
| 739 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); | 748 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); |
| 740 if (!pFirstPiece) | 749 if (!pFirstPiece) |
| 741 return; | 750 return; |
| 742 | 751 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 756 int32_t iPieces = pLine->GetSize(); | 765 int32_t iPieces = pLine->GetSize(); |
| 757 for (int32_t j = 0; j < iPieces; j++) { | 766 for (int32_t j = 0; j < iPieces; j++) { |
| 758 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); | 767 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); |
| 759 if (bVertical) | 768 if (bVertical) |
| 760 pPiece->rtPiece.left += fInc; | 769 pPiece->rtPiece.left += fInc; |
| 761 else | 770 else |
| 762 pPiece->rtPiece.top += fInc; | 771 pPiece->rtPiece.top += fInc; |
| 763 } | 772 } |
| 764 } | 773 } |
| 765 } | 774 } |
| 775 |
| 766 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { | 776 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { |
| 767 if (!m_pRenderDevice) | 777 if (!m_pRenderDevice) |
| 768 return; | 778 return; |
| 769 | 779 |
| 770 int32_t iLines = m_ttoLines.GetSize(); | 780 int32_t iLines = m_ttoLines.GetSize(); |
| 771 if (iLines < 1) | 781 if (iLines < 1) |
| 772 return; | 782 return; |
| 773 | 783 |
| 774 CFDE_Brush* pBrush = new CFDE_Brush; | 784 CFDE_Brush* pBrush = new CFDE_Brush; |
| 775 pBrush->SetColor(m_TxtColor); | 785 pBrush->SetColor(m_TxtColor); |
| 776 CFDE_Pen* pPen = nullptr; | 786 CFDE_Pen* pPen = nullptr; |
| 777 m_pRenderDevice->SaveState(); | 787 m_pRenderDevice->SaveState(); |
| 778 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { | 788 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { |
| 779 m_pRenderDevice->SetClipRect(rtClip); | 789 m_pRenderDevice->SetClipRect(rtClip); |
| 780 } | 790 } |
| 781 for (int32_t i = 0; i < iLines; i++) { | 791 for (int32_t i = 0; i < iLines; i++) { |
| 782 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 792 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
| 783 int32_t iPieces = pLine->GetSize(); | 793 int32_t iPieces = pLine->GetSize(); |
| 784 for (int32_t j = 0; j < iPieces; j++) { | 794 for (int32_t j = 0; j < iPieces; j++) { |
| 785 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); | 795 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); |
| 786 if (!pPiece) | 796 if (!pPiece) |
| 787 continue; | 797 continue; |
| 788 | 798 |
| 789 int32_t iCount = GetDisplayPos(pPiece); | 799 int32_t iCount = GetDisplayPos(pPiece); |
| 790 if (iCount > 0) { | 800 if (iCount > 0) { |
| 791 m_pRenderDevice->DrawString(pBrush, m_pFont, m_pCharPos, iCount, | 801 m_pRenderDevice->DrawString(pBrush, m_pFont, m_CharPos.data(), iCount, |
| 792 m_fFontSize, &m_Matrix); | 802 m_fFontSize, &m_Matrix); |
| 793 } | 803 } |
| 794 DrawLine(pPiece, pPen); | 804 DrawLine(pPiece, pPen); |
| 795 } | 805 } |
| 796 } | 806 } |
| 797 m_pRenderDevice->RestoreState(); | 807 m_pRenderDevice->RestoreState(); |
| 798 delete pBrush; | 808 delete pBrush; |
| 799 delete pPen; | 809 delete pPen; |
| 800 } | 810 } |
| 801 | 811 |
| 802 int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { | 812 int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { |
| 803 FX_TXTRUN tr = ToTextRun(pPiece); | 813 FX_TXTRUN tr = ToTextRun(pPiece); |
| 804 ExpandBuffer(tr.iLength, 2); | 814 ExpandBuffer(tr.iLength, 2); |
| 805 return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); | 815 return m_pTxtBreak->GetDisplayPos(&tr, m_CharPos.data()); |
| 806 } | 816 } |
| 807 | 817 |
| 808 int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { | 818 int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { |
| 809 FX_TXTRUN tr = ToTextRun(pPiece); | 819 FX_TXTRUN tr = ToTextRun(pPiece); |
| 810 m_rectArray.RemoveAll(); | 820 m_rectArray.RemoveAll(); |
| 811 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); | 821 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); |
| 812 } | 822 } |
| 813 | 823 |
| 814 FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { | 824 FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { |
| 815 FX_TXTRUN tr; | 825 FX_TXTRUN tr; |
| 816 tr.wsStr = m_wsText + pPiece->iStartChar; | 826 tr.wsStr = m_wsText + pPiece->iStartChar; |
| 817 tr.pWidths = m_pCharWidths + pPiece->iStartChar; | 827 tr.pWidths = &m_CharWidths[pPiece->iStartChar]; |
| 818 tr.iLength = pPiece->iChars; | 828 tr.iLength = pPiece->iChars; |
| 819 tr.pFont = m_pFont; | 829 tr.pFont = m_pFont; |
| 820 tr.fFontSize = m_fFontSize; | 830 tr.fFontSize = m_fFontSize; |
| 821 tr.dwStyles = m_dwTxtBkStyles; | 831 tr.dwStyles = m_dwTxtBkStyles; |
| 822 tr.dwCharStyles = pPiece->dwCharStyles; | 832 tr.dwCharStyles = pPiece->dwCharStyles; |
| 823 tr.wLineBreakChar = m_wParagraphBkChar; | 833 tr.wLineBreakChar = m_wParagraphBkChar; |
| 824 tr.pRect = &pPiece->rtPiece; | 834 tr.pRect = &pPiece->rtPiece; |
| 825 return tr; | 835 return tr; |
| 826 } | 836 } |
| 827 | 837 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { | 925 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { |
| 916 if (index >= m_iPieceCount) { | 926 if (index >= m_iPieceCount) { |
| 917 index = m_pieces.Add(ttoPiece) + 1; | 927 index = m_pieces.Add(ttoPiece) + 1; |
| 918 m_iPieceCount++; | 928 m_iPieceCount++; |
| 919 } else { | 929 } else { |
| 920 FDE_TTOPIECE& piece = m_pieces.GetAt(index); | 930 FDE_TTOPIECE& piece = m_pieces.GetAt(index); |
| 921 piece = ttoPiece; | 931 piece = ttoPiece; |
| 922 } | 932 } |
| 923 return index; | 933 return index; |
| 924 } | 934 } |
| 935 |
| 925 int32_t CFDE_TTOLine::GetSize() const { | 936 int32_t CFDE_TTOLine::GetSize() const { |
| 926 return m_iPieceCount; | 937 return m_iPieceCount; |
| 927 } | 938 } |
| 939 |
| 928 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { | 940 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { |
| 929 if (index >= m_iPieceCount) { | 941 if (index >= m_iPieceCount) { |
| 930 return nullptr; | 942 return nullptr; |
| 931 } | 943 } |
| 932 return m_pieces.GetPtrAt(index); | 944 return m_pieces.GetPtrAt(index); |
| 933 } | 945 } |
| 946 |
| 934 void CFDE_TTOLine::RemoveLast(int32_t iCount) { | 947 void CFDE_TTOLine::RemoveLast(int32_t iCount) { |
| 935 m_pieces.RemoveLast(iCount); | 948 m_pieces.RemoveLast(iCount); |
| 936 } | 949 } |
| 950 |
| 937 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { | 951 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { |
| 938 m_pieces.RemoveAll(bLeaveMemory); | 952 m_pieces.RemoveAll(bLeaveMemory); |
| 939 } | 953 } |
| OLD | NEW |