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 "../../include/pdfwindow/PDFWindow.h" | 7 #include "../../include/pdfwindow/PDFWindow.h" |
8 #include "../../include/pdfwindow/PWL_Wnd.h" | 8 #include "../../include/pdfwindow/PWL_Wnd.h" |
9 #include "../../include/pdfwindow/PWL_Icon.h" | 9 #include "../../include/pdfwindow/PWL_Icon.h" |
10 #include "../../include/pdfwindow/PWL_Utils.h" | 10 #include "../../include/pdfwindow/PWL_Utils.h" |
11 | 11 |
12 /* ------------------------------- CPWL_Image ----------------------------------
*/ | 12 /* ------------------------------- CPWL_Image ---------------------------------- |
13 | 13 */ |
14 CPWL_Image::CPWL_Image() : m_pPDFStream(NULL) | 14 |
15 { | 15 CPWL_Image::CPWL_Image() : m_pPDFStream(NULL) {} |
16 } | 16 |
17 | 17 CPWL_Image::~CPWL_Image() {} |
18 CPWL_Image::~CPWL_Image() | 18 |
19 { | 19 CFX_ByteString CPWL_Image::GetImageAppStream() { |
20 } | 20 CFX_ByteTextBuf sAppStream; |
21 | 21 |
22 CFX_ByteString CPWL_Image::GetImageAppStream() | 22 CFX_ByteString sAlias = GetImageAlias(); |
23 { | 23 CPDF_Rect rcPlate = GetClientRect(); |
24 CFX_ByteTextBuf sAppStream; | 24 CPDF_Matrix mt; |
25 | 25 mt.SetReverse(GetImageMatrix()); |
26 CFX_ByteString sAlias = GetImageAlias(); | 26 |
27 CPDF_Rect rcPlate = GetClientRect(); | 27 FX_FLOAT fHScale = 1.0f; |
28 CPDF_Matrix mt; | 28 FX_FLOAT fVScale = 1.0f; |
29 mt.SetReverse(GetImageMatrix()); | 29 GetScale(fHScale, fVScale); |
30 | 30 |
31 FX_FLOAT fHScale = 1.0f; | 31 FX_FLOAT fx = 0.0f; |
32 FX_FLOAT fVScale = 1.0f; | 32 FX_FLOAT fy = 0.0f; |
33 GetScale(fHScale,fVScale); | 33 GetImageOffset(fx, fy); |
34 | 34 |
35 FX_FLOAT fx = 0.0f; | 35 if (m_pPDFStream && sAlias.GetLength() > 0) { |
36 FX_FLOAT fy = 0.0f; | 36 sAppStream << "q\n"; |
37 GetImageOffset(fx,fy); | 37 sAppStream << rcPlate.left << " " << rcPlate.bottom << " " |
38 | 38 << rcPlate.right - rcPlate.left << " " |
39 if (m_pPDFStream && sAlias.GetLength()>0) | 39 << rcPlate.top - rcPlate.bottom << " re W n\n"; |
40 { | 40 |
41 sAppStream << "q\n"; | 41 sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx |
42 sAppStream << rcPlate.left << " " << rcPlate.bottom << " " | 42 << " " << rcPlate.bottom + fy << " cm\n"; |
43 << rcPlate.right - rcPlate.left << " " << rcPlate.top -
rcPlate.bottom << " re W n\n"; | 43 sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " |
44 | 44 << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n"; |
45 sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.le
ft + fx << " " << rcPlate.bottom + fy << " cm\n"; | 45 |
46 sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC()
<< " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n"; | 46 sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" |
47 | 47 << "Q\n"; |
48 sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n"; | 48 } |
49 } | 49 |
50 | 50 return sAppStream.GetByteString(); |
51 return sAppStream.GetByteString(); | 51 } |
52 } | 52 |
53 | 53 void CPWL_Image::SetPDFStream(CPDF_Stream* pStream) { |
54 void CPWL_Image::SetPDFStream(CPDF_Stream * pStream) | 54 m_pPDFStream = pStream; |
55 { | 55 } |
56 m_pPDFStream = pStream; | 56 |
57 } | 57 CPDF_Stream* CPWL_Image::GetPDFStream() { |
58 | 58 return m_pPDFStream; |
59 CPDF_Stream * CPWL_Image::GetPDFStream() | 59 } |
60 { | 60 |
61 return m_pPDFStream; | 61 void CPWL_Image::GetImageSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight) { |
62 } | 62 fWidth = 0.0f; |
63 | 63 fHeight = 0.0f; |
64 void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight) | 64 |
65 { | 65 if (m_pPDFStream) { |
66 fWidth = 0.0f; | 66 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { |
67 fHeight = 0.0f; | 67 CPDF_Rect rect = pDict->GetRect("BBox"); |
68 | 68 |
69 if (m_pPDFStream) | 69 fWidth = rect.right - rect.left; |
70 { | 70 fHeight = rect.top - rect.bottom; |
71 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) | 71 } |
72 { | 72 } |
73 CPDF_Rect rect = pDict->GetRect("BBox"); | 73 } |
74 | 74 |
75 fWidth = rect.right - rect.left; | 75 CPDF_Matrix CPWL_Image::GetImageMatrix() { |
76 fHeight = rect.top - rect.bottom; | 76 if (m_pPDFStream) { |
77 } | 77 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { |
78 } | 78 return pDict->GetMatrix("Matrix"); |
79 } | 79 } |
80 | 80 } |
81 CPDF_Matrix CPWL_Image::GetImageMatrix() | 81 |
82 { | 82 return CPDF_Matrix(); |
83 if (m_pPDFStream) | 83 } |
84 { | 84 |
85 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) | 85 CFX_ByteString CPWL_Image::GetImageAlias() { |
86 { | 86 if (m_sImageAlias.IsEmpty()) { |
87 return pDict->GetMatrix("Matrix"); | 87 if (m_pPDFStream) { |
88 } | 88 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { |
89 } | 89 return pDict->GetString("Name"); |
90 | 90 } |
91 return CPDF_Matrix(); | 91 } |
92 } | 92 } else |
93 | 93 return m_sImageAlias; |
94 CFX_ByteString CPWL_Image::GetImageAlias() | 94 |
95 { | 95 return CFX_ByteString(); |
96 if (m_sImageAlias.IsEmpty()) | 96 } |
97 { | 97 |
98 if (m_pPDFStream) | 98 void CPWL_Image::SetImageAlias(const FX_CHAR* sImageAlias) { |
99 { | 99 m_sImageAlias = sImageAlias; |
100 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) | 100 } |
101 { | 101 |
102 return pDict->GetString("Name"); | 102 void CPWL_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { |
103 } | 103 fHScale = 1.0f; |
104 } | 104 fVScale = 1.0f; |
105 } | 105 } |
106 else | 106 |
107 return m_sImageAlias; | 107 void CPWL_Image::GetImageOffset(FX_FLOAT& x, FX_FLOAT& y) { |
108 | 108 x = 0.0f; |
109 return CFX_ByteString(); | 109 y = 0.0f; |
110 } | 110 } |
111 | 111 |
112 void CPWL_Image::SetImageAlias(const FX_CHAR* sImageAlias) | 112 /* ------------------------------- CPWL_Icon ---------------------------------- |
113 { | 113 */ |
114 m_sImageAlias = sImageAlias; | 114 |
115 } | 115 CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL) {} |
116 | 116 |
117 void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale) | 117 CPWL_Icon::~CPWL_Icon() {} |
118 { | 118 |
119 fHScale = 1.0f; | 119 int32_t CPWL_Icon::GetScaleMethod() { |
120 fVScale = 1.0f; | 120 if (m_pIconFit) |
121 } | 121 return m_pIconFit->GetScaleMethod(); |
122 | 122 |
123 | 123 return 0; |
124 void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y) | 124 } |
125 { | 125 |
126 x = 0.0f; | 126 FX_BOOL CPWL_Icon::IsProportionalScale() { |
127 y = 0.0f; | 127 if (m_pIconFit) |
128 } | 128 return m_pIconFit->IsProportionalScale(); |
129 | 129 |
130 /* ------------------------------- CPWL_Icon ----------------------------------
*/ | 130 return FALSE; |
131 | 131 } |
132 CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL) | 132 |
133 { | 133 void CPWL_Icon::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { |
134 } | 134 if (m_pIconFit) { |
135 | 135 // m_pIconFit->GetIconPosition(fLeft,fBottom); |
136 CPWL_Icon::~CPWL_Icon() | 136 fLeft = 0.0f; |
137 { | 137 fBottom = 0.0f; |
138 } | 138 CPDF_Array* pA = |
139 | 139 m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetArray("A") : NULL; |
140 int32_t CPWL_Icon::GetScaleMethod() | 140 if (pA != NULL) { |
141 { | 141 FX_DWORD dwCount = pA->GetCount(); |
142 if (m_pIconFit) | 142 if (dwCount > 0) |
143 return m_pIconFit->GetScaleMethod(); | 143 fLeft = pA->GetNumber(0); |
144 | 144 if (dwCount > 1) |
145 return 0; | 145 fBottom = pA->GetNumber(1); |
146 } | 146 } |
147 | 147 } else { |
148 FX_BOOL CPWL_Icon::IsProportionalScale() | 148 fLeft = 0.0f; |
149 { | 149 fBottom = 0.0f; |
150 if (m_pIconFit) | 150 } |
151 return m_pIconFit->IsProportionalScale(); | 151 } |
152 | 152 |
153 return FALSE; | 153 FX_BOOL CPWL_Icon::GetFittingBounds() { |
154 } | 154 if (m_pIconFit) |
155 | 155 return m_pIconFit->GetFittingBounds(); |
156 void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom) | 156 |
157 { | 157 return FALSE; |
158 if (m_pIconFit) | 158 } |
159 { | 159 |
160 //m_pIconFit->GetIconPosition(fLeft,fBottom); | 160 void CPWL_Icon::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { |
161 fLeft = 0.0f; | 161 fHScale = 1.0f; |
162 fBottom = 0.0f; | 162 fVScale = 1.0f; |
163 CPDF_Array* pA = m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetA
rray("A") : NULL; | 163 |
164 if (pA != NULL) | 164 if (m_pPDFStream) { |
165 { | 165 FX_FLOAT fImageWidth, fImageHeight; |
166 FX_DWORD dwCount = pA->GetCount(); | 166 FX_FLOAT fPlateWidth, fPlateHeight; |
167 if (dwCount > 0) fLeft = pA->GetNumber(0); | 167 |
168 if (dwCount > 1) fBottom = pA->GetNumber(1); | 168 CPDF_Rect rcPlate = GetClientRect(); |
169 } | 169 fPlateWidth = rcPlate.right - rcPlate.left; |
170 } | 170 fPlateHeight = rcPlate.top - rcPlate.bottom; |
171 else | 171 |
172 { | 172 GetImageSize(fImageWidth, fImageHeight); |
173 fLeft = 0.0f; | 173 |
174 fBottom = 0.0f; | 174 int32_t nScaleMethod = GetScaleMethod(); |
175 } | 175 |
176 } | 176 switch (nScaleMethod) { |
177 | 177 default: |
178 FX_BOOL CPWL_Icon::GetFittingBounds() | 178 case 0: |
179 { | 179 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f); |
180 if (m_pIconFit) | 180 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f); |
181 return m_pIconFit->GetFittingBounds(); | 181 break; |
182 | 182 case 1: |
183 return FALSE; | 183 if (fPlateWidth < fImageWidth) |
184 } | 184 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f); |
185 | 185 if (fPlateHeight < fImageHeight) |
186 void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale) | 186 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f); |
187 { | 187 break; |
188 fHScale = 1.0f; | 188 case 2: |
189 fVScale = 1.0f; | 189 if (fPlateWidth > fImageWidth) |
190 | 190 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f); |
191 if (m_pPDFStream) | 191 if (fPlateHeight > fImageHeight) |
192 { | 192 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f); |
193 FX_FLOAT fImageWidth,fImageHeight; | 193 break; |
194 FX_FLOAT fPlateWidth,fPlateHeight; | 194 case 3: |
195 | 195 break; |
196 CPDF_Rect rcPlate = GetClientRect(); | 196 } |
197 fPlateWidth = rcPlate.right - rcPlate.left; | 197 |
198 fPlateHeight = rcPlate.top - rcPlate.bottom; | 198 FX_FLOAT fMinScale; |
199 | 199 if (IsProportionalScale()) { |
200 GetImageSize(fImageWidth,fImageHeight); | 200 fMinScale = PWL_MIN(fHScale, fVScale); |
201 | 201 fHScale = fMinScale; |
202 int32_t nScaleMethod = GetScaleMethod(); | 202 fVScale = fMinScale; |
203 | 203 } |
204 switch (nScaleMethod) | 204 } |
205 { | 205 } |
206 default: | 206 |
207 case 0: | 207 void CPWL_Icon::GetImageOffset(FX_FLOAT& x, FX_FLOAT& y) { |
208 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f); | 208 FX_FLOAT fLeft, fBottom; |
209 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f); | 209 |
210 break; | 210 GetIconPosition(fLeft, fBottom); |
211 case 1: | 211 x = 0.0f; |
212 if (fPlateWidth < fImageWidth) | 212 y = 0.0f; |
213 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f
); | 213 |
214 if (fPlateHeight < fImageHeight) | 214 FX_FLOAT fImageWidth, fImageHeight; |
215 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.
0f); | 215 GetImageSize(fImageWidth, fImageHeight); |
216 break; | 216 |
217 case 2: | 217 FX_FLOAT fHScale, fVScale; |
218 if (fPlateWidth > fImageWidth) | 218 GetScale(fHScale, fVScale); |
219 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f
); | 219 |
220 if (fPlateHeight > fImageHeight) | 220 FX_FLOAT fImageFactWidth = fImageWidth * fHScale; |
221 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.
0f); | 221 FX_FLOAT fImageFactHeight = fImageHeight * fVScale; |
222 break; | 222 |
223 case 3: | 223 FX_FLOAT fPlateWidth, fPlateHeight; |
224 break; | 224 CPDF_Rect rcPlate = GetClientRect(); |
225 } | 225 fPlateWidth = rcPlate.right - rcPlate.left; |
226 | 226 fPlateHeight = rcPlate.top - rcPlate.bottom; |
227 FX_FLOAT fMinScale; | 227 |
228 if (IsProportionalScale()) | 228 x = (fPlateWidth - fImageFactWidth) * fLeft; |
229 { | 229 y = (fPlateHeight - fImageFactHeight) * fBottom; |
230 fMinScale = PWL_MIN(fHScale,fVScale); | 230 } |
231 fHScale = fMinScale; | |
232 fVScale = fMinScale; | |
233 } | |
234 } | |
235 } | |
236 | |
237 void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y) | |
238 { | |
239 FX_FLOAT fLeft,fBottom; | |
240 | |
241 GetIconPosition(fLeft, fBottom); | |
242 x = 0.0f; | |
243 y = 0.0f; | |
244 | |
245 FX_FLOAT fImageWidth,fImageHeight; | |
246 GetImageSize(fImageWidth,fImageHeight); | |
247 | |
248 FX_FLOAT fHScale,fVScale; | |
249 GetScale(fHScale,fVScale); | |
250 | |
251 FX_FLOAT fImageFactWidth = fImageWidth * fHScale; | |
252 FX_FLOAT fImageFactHeight = fImageHeight * fVScale; | |
253 | |
254 FX_FLOAT fPlateWidth,fPlateHeight; | |
255 CPDF_Rect rcPlate = GetClientRect(); | |
256 fPlateWidth = rcPlate.right - rcPlate.left; | |
257 fPlateHeight = rcPlate.top - rcPlate.bottom; | |
258 | |
259 x = (fPlateWidth - fImageFactWidth) * fLeft; | |
260 y = (fPlateHeight - fImageFactHeight) * fBottom; | |
261 } | |
262 | |
OLD | NEW |