OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/fxedit/include/fx_edit.h" | |
8 #include "fpdfsdk/pdfwindow/PWL_Label.h" | |
9 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | |
10 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | |
11 | |
12 CPWL_Label::CPWL_Label() : m_pEdit(IFX_Edit::NewEdit()) {} | |
13 | |
14 CPWL_Label::~CPWL_Label() { | |
15 IFX_Edit::DelEdit(m_pEdit); | |
16 } | |
17 | |
18 CFX_ByteString CPWL_Label::GetClassName() const { | |
19 return "CPWL_Label"; | |
20 } | |
21 | |
22 void CPWL_Label::OnCreated() { | |
23 SetParamByFlag(); | |
24 SetFontSize(GetCreationParam().fFontSize); | |
25 | |
26 m_pEdit->SetFontMap(GetFontMap()); | |
27 m_pEdit->Initialize(); | |
28 | |
29 if (HasFlag(PES_TEXTOVERFLOW)) { | |
30 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); | |
31 m_pEdit->SetTextOverflow(TRUE); | |
32 } | |
33 } | |
34 | |
35 void CPWL_Label::SetText(const FX_WCHAR* csText) { | |
36 m_pEdit->SetText(csText); | |
37 } | |
38 | |
39 void CPWL_Label::RePosChildWnd() { | |
40 m_pEdit->SetPlateRect(GetClientRect()); | |
41 } | |
42 | |
43 void CPWL_Label::SetFontSize(FX_FLOAT fFontSize) { | |
44 m_pEdit->SetFontSize(fFontSize); | |
45 } | |
46 | |
47 FX_FLOAT CPWL_Label::GetFontSize() const { | |
48 return m_pEdit->GetFontSize(); | |
49 } | |
50 | |
51 void CPWL_Label::SetParamByFlag() { | |
52 if (HasFlag(PES_LEFT)) { | |
53 m_pEdit->SetAlignmentH(0); | |
54 } else if (HasFlag(PES_MIDDLE)) { | |
55 m_pEdit->SetAlignmentH(1); | |
56 } else if (HasFlag(PES_RIGHT)) { | |
57 m_pEdit->SetAlignmentH(2); | |
58 } else { | |
59 m_pEdit->SetAlignmentH(0); | |
60 } | |
61 | |
62 if (HasFlag(PES_TOP)) { | |
63 m_pEdit->SetAlignmentV(0); | |
64 } else if (HasFlag(PES_CENTER)) { | |
65 m_pEdit->SetAlignmentV(1); | |
66 } else if (HasFlag(PES_BOTTOM)) { | |
67 m_pEdit->SetAlignmentV(2); | |
68 } else { | |
69 m_pEdit->SetAlignmentV(0); | |
70 } | |
71 | |
72 if (HasFlag(PES_PASSWORD)) { | |
73 m_pEdit->SetPasswordChar('*'); | |
74 } | |
75 | |
76 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE)); | |
77 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN)); | |
78 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE)); | |
79 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL)); | |
80 } | |
81 | |
82 void CPWL_Label::DrawThisAppearance(CFX_RenderDevice* pDevice, | |
83 CFX_Matrix* pUser2Device) { | |
84 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); | |
85 | |
86 GetClientRect(); | |
87 | |
88 CFX_FloatRect rcClip; | |
89 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); | |
90 CPVT_WordRange* pRange = nullptr; | |
91 | |
92 if (!HasFlag(PES_TEXTOVERFLOW)) { | |
93 rcClip = GetClientRect(); | |
94 pRange = &wrRange; | |
95 } | |
96 CFX_SystemHandler* pSysHandler = GetSystemHandler(); | |
97 IFX_Edit::DrawEdit( | |
98 pDevice, pUser2Device, m_pEdit, | |
99 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), | |
100 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), | |
101 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, nullptr); | |
102 } | |
103 | |
104 void CPWL_Label::SetHorzScale(int32_t nHorzScale) { | |
105 m_pEdit->SetHorzScale(nHorzScale); | |
106 } | |
107 | |
108 void CPWL_Label::SetCharSpace(FX_FLOAT fCharSpace) { | |
109 m_pEdit->SetCharSpace(fCharSpace); | |
110 } | |
111 | |
112 CFX_FloatRect CPWL_Label::GetContentRect() const { | |
113 return m_pEdit->GetContentRect(); | |
114 } | |
115 | |
116 void CPWL_Label::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { | |
117 CPWL_Wnd::GetThisAppearanceStream(sAppStream); | |
118 | |
119 sAppStream << GetTextAppearanceStream(CFX_FloatPoint(0.0f, 0.0f)).AsStringC(); | |
120 } | |
121 | |
122 CFX_ByteString CPWL_Label::GetTextAppearanceStream( | |
123 const CFX_FloatPoint& ptOffset) const { | |
124 CFX_ByteTextBuf sRet; | |
125 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset); | |
126 if (sEdit.GetLength() > 0) { | |
127 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() | |
128 << sEdit.AsStringC() << "ET\n"; | |
129 } | |
130 return sRet.MakeString(); | |
131 } | |
132 | |
133 CFX_WideString CPWL_Label::GetText() const { | |
134 return m_pEdit->GetText(); | |
135 } | |
136 | |
137 void CPWL_Label::SetLimitChar(int32_t nLimitChar) { | |
138 m_pEdit->SetLimitChar(nLimitChar); | |
139 } | |
140 | |
141 int32_t CPWL_Label::GetTotalWords() { | |
142 return m_pEdit->GetTotalWords(); | |
143 } | |
OLD | NEW |