Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_Icon.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
18 CPWL_Image::~CPWL_Image() 18 CPWL_Image::~CPWL_Image() {
19 { 19 }
20 } 20
21 21 CFX_ByteString CPWL_Image::GetImageAppStream() {
22 CFX_ByteString CPWL_Image::GetImageAppStream() 22 CFX_ByteTextBuf sAppStream;
23 { 23
24 CFX_ByteTextBuf sAppStream; 24 CFX_ByteString sAlias = this->GetImageAlias();
25 25 CPDF_Rect rcPlate = GetClientRect();
26 CFX_ByteString sAlias = this->GetImageAlias(); 26 CPDF_Matrix mt;
27 CPDF_Rect rcPlate = GetClientRect(); 27 mt.SetReverse(GetImageMatrix());
28 CPDF_Matrix mt; 28
29 mt.SetReverse(GetImageMatrix()); 29 FX_FLOAT fHScale = 1.0f;
30 30 FX_FLOAT fVScale = 1.0f;
31 FX_FLOAT fHScale = 1.0f; 31 GetScale(fHScale, fVScale);
32 FX_FLOAT fVScale = 1.0f; 32
33 GetScale(fHScale,fVScale); 33 FX_FLOAT fx = 0.0f;
34 34 FX_FLOAT fy = 0.0f;
35 FX_FLOAT fx = 0.0f; 35 GetImageOffset(fx, fy);
36 FX_FLOAT fy = 0.0f; 36
37 GetImageOffset(fx,fy); 37 if (m_pPDFStream && sAlias.GetLength() > 0) {
38 38 sAppStream << "q\n";
39 if (m_pPDFStream && sAlias.GetLength()>0) 39 sAppStream << rcPlate.left << " " << rcPlate.bottom << " "
40 { 40 << rcPlate.right - rcPlate.left << " "
41 sAppStream << "q\n"; 41 << rcPlate.top - rcPlate.bottom << " re W n\n";
42 sAppStream << rcPlate.left << " " << rcPlate.bottom << " " 42
43 << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n"; 43 sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx
44 44 << " " << rcPlate.bottom + fy << " cm\n";
45 sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.le ft + fx << " " << rcPlate.bottom + fy << " cm\n"; 45 sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " "
46 sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n"; 46 << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n";
47 47
48 sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n"; 48 sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n"
49 } 49 << "Q\n";
50 50 }
51 return sAppStream.GetByteString(); 51
52 } 52 return sAppStream.GetByteString();
53 53 }
54 void CPWL_Image::SetPDFStream(CPDF_Stream * pStream) 54
55 { 55 void CPWL_Image::SetPDFStream(CPDF_Stream* pStream) {
56 m_pPDFStream = pStream; 56 m_pPDFStream = pStream;
57 } 57 }
58 58
59 CPDF_Stream * CPWL_Image::GetPDFStream() 59 CPDF_Stream* CPWL_Image::GetPDFStream() {
60 { 60 return this->m_pPDFStream;
61 return this->m_pPDFStream; 61 }
62 } 62
63 63 void CPWL_Image::GetImageSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight) {
64 void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight) 64 fWidth = 0.0f;
65 { 65 fHeight = 0.0f;
66 fWidth = 0.0f; 66
67 fHeight = 0.0f; 67 if (m_pPDFStream) {
68 68 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) {
69 if (m_pPDFStream) 69 CPDF_Rect rect = pDict->GetRect("BBox");
70 { 70
71 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) 71 fWidth = rect.right - rect.left;
72 { 72 fHeight = rect.top - rect.bottom;
73 CPDF_Rect rect = pDict->GetRect("BBox"); 73 }
74 74 }
75 fWidth = rect.right - rect.left; 75 }
76 fHeight = rect.top - rect.bottom; 76
77 } 77 CPDF_Matrix CPWL_Image::GetImageMatrix() {
78 } 78 if (m_pPDFStream) {
79 } 79 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) {
80 80 return pDict->GetMatrix("Matrix");
81 CPDF_Matrix CPWL_Image::GetImageMatrix() 81 }
82 { 82 }
83 if (m_pPDFStream) 83
84 { 84 return CPDF_Matrix();
85 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) 85 }
86 { 86
87 return pDict->GetMatrix("Matrix"); 87 CFX_ByteString CPWL_Image::GetImageAlias() {
88 } 88 if (m_sImageAlias.IsEmpty()) {
89 } 89 if (m_pPDFStream) {
90 90 if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) {
91 return CPDF_Matrix(); 91 return pDict->GetString("Name");
92 } 92 }
93 93 }
94 CFX_ByteString CPWL_Image::GetImageAlias() 94 } else
95 { 95 return m_sImageAlias;
96 if (m_sImageAlias.IsEmpty()) 96
97 { 97 return CFX_ByteString();
98 if (m_pPDFStream) 98 }
99 { 99
100 if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict()) 100 void CPWL_Image::SetImageAlias(FX_LPCSTR sImageAlias) {
101 { 101 m_sImageAlias = sImageAlias;
102 return pDict->GetString("Name"); 102 }
103 } 103
104 } 104 void CPWL_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) {
105 } 105 fHScale = 1.0f;
106 else 106 fVScale = 1.0f;
107 return m_sImageAlias; 107 }
108 108
109 return CFX_ByteString(); 109 void CPWL_Image::GetImageOffset(FX_FLOAT& x, FX_FLOAT& y) {
110 } 110 x = 0.0f;
111 111 y = 0.0f;
112 void CPWL_Image::SetImageAlias(FX_LPCSTR sImageAlias) 112 }
113 { 113
114 m_sImageAlias = sImageAlias; 114 /* ------------------------------- CPWL_Icon ----------------------------------
115 } 115 */
116 116
117 void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale) 117 CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL) {
118 { 118 }
119 fHScale = 1.0f; 119
120 fVScale = 1.0f; 120 CPWL_Icon::~CPWL_Icon() {
121 } 121 }
122 122
123 123 FX_INT32 CPWL_Icon::GetScaleMethod() {
124 void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y) 124 if (m_pIconFit)
125 { 125 return m_pIconFit->GetScaleMethod();
126 x = 0.0f; 126
127 y = 0.0f; 127 return 0;
128 } 128 }
129 129
130 /* ------------------------------- CPWL_Icon ---------------------------------- */ 130 FX_BOOL CPWL_Icon::IsProportionalScale() {
131 131 if (m_pIconFit)
132 CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL) 132 return m_pIconFit->IsProportionalScale();
133 { 133
134 } 134 return FALSE;
135 135 }
136 CPWL_Icon::~CPWL_Icon() 136
137 { 137 void CPWL_Icon::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) {
138 } 138 if (m_pIconFit) {
139 139 // m_pIconFit->GetIconPosition(fLeft,fBottom);
140 FX_INT32 CPWL_Icon::GetScaleMethod() 140 fLeft = 0.0f;
141 { 141 fBottom = 0.0f;
142 if (m_pIconFit) 142 CPDF_Array* pA =
143 return m_pIconFit->GetScaleMethod(); 143 m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetArray("A") : NULL;
144 144 if (pA != NULL) {
145 return 0; 145 FX_DWORD dwCount = pA->GetCount();
146 } 146 if (dwCount > 0)
147 147 fLeft = pA->GetNumber(0);
148 FX_BOOL CPWL_Icon::IsProportionalScale() 148 if (dwCount > 1)
149 { 149 fBottom = pA->GetNumber(1);
150 if (m_pIconFit) 150 }
151 return m_pIconFit->IsProportionalScale(); 151 } else {
152 152 fLeft = 0.0f;
153 return FALSE; 153 fBottom = 0.0f;
154 } 154 }
155 155 }
156 void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom) 156
157 { 157 FX_BOOL CPWL_Icon::GetFittingBounds() {
158 if (m_pIconFit) 158 if (m_pIconFit)
159 { 159 return m_pIconFit->GetFittingBounds();
160 //m_pIconFit->GetIconPosition(fLeft,fBottom); 160
161 fLeft = 0.0f; 161 return FALSE;
162 fBottom = 0.0f; 162 }
163 CPDF_Array* pA = m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetA rray("A") : NULL; 163
164 if (pA != NULL) 164 void CPWL_Icon::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) {
165 { 165 fHScale = 1.0f;
166 FX_DWORD dwCount = pA->GetCount(); 166 fVScale = 1.0f;
167 if (dwCount > 0) fLeft = pA->GetNumber(0); 167
168 if (dwCount > 1) fBottom = pA->GetNumber(1); 168 if (m_pPDFStream) {
169 } 169 FX_FLOAT fImageWidth, fImageHeight;
170 } 170 FX_FLOAT fPlateWidth, fPlateHeight;
171 else 171
172 { 172 CPDF_Rect rcPlate = this->GetClientRect();
173 fLeft = 0.0f; 173 fPlateWidth = rcPlate.right - rcPlate.left;
174 fBottom = 0.0f; 174 fPlateHeight = rcPlate.top - rcPlate.bottom;
175 } 175
176 } 176 GetImageSize(fImageWidth, fImageHeight);
177 177
178 FX_BOOL CPWL_Icon::GetFittingBounds() 178 FX_INT32 nScaleMethod = this->GetScaleMethod();
179 { 179
180 if (m_pIconFit) 180 /*
181 return m_pIconFit->GetFittingBounds(); 181 enum ScaleMethod
182 182 {
183 return FALSE; 183 Always = 0, //A, Always scale
184 } 184 Bigger, //B, Scale only when the icon is bigger than the
185 185 annotation rectangle
186 void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale) 186 Smaller, //S, Scale only when the icon is smaller then the
187 { 187 annotation rectangle
188 fHScale = 1.0f; 188 Never //N, Never scale
189 fVScale = 1.0f; 189 };
190 190 */
191 if (m_pPDFStream) 191
192 { 192 switch (nScaleMethod) {
193 FX_FLOAT fImageWidth,fImageHeight; 193 default:
194 FX_FLOAT fPlateWidth,fPlateHeight; 194 case 0:
195 195 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f);
196 CPDF_Rect rcPlate = this->GetClientRect(); 196 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f);
197 fPlateWidth = rcPlate.right - rcPlate.left; 197 break;
198 fPlateHeight = rcPlate.top - rcPlate.bottom; 198 case 1:
199 199 if (fPlateWidth < fImageWidth)
200 GetImageSize(fImageWidth,fImageHeight); 200 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f);
201 201 if (fPlateHeight < fImageHeight)
202 FX_INT32 nScaleMethod = this->GetScaleMethod(); 202 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f);
203 203 break;
204 /* 204 case 2:
205 enum ScaleMethod 205 if (fPlateWidth > fImageWidth)
206 { 206 fHScale = fPlateWidth / PWL_MAX(fImageWidth, 1.0f);
207 Always = 0, //A, Always scale 207 if (fPlateHeight > fImageHeight)
208 Bigger, //B, Scale only when the icon is bigger than the annotation rectangle 208 fVScale = fPlateHeight / PWL_MAX(fImageHeight, 1.0f);
209 Smaller, //S, Scale only when the icon is smaller then the annotation rectangle 209 break;
210 Never //N, Never scale 210 case 3:
211 }; 211 break;
212 */ 212 }
213 213
214 switch (nScaleMethod) 214 FX_FLOAT fMinScale;
215 { 215 if (IsProportionalScale()) {
216 default: 216 fMinScale = PWL_MIN(fHScale, fVScale);
217 case 0: 217 fHScale = fMinScale;
218 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f); 218 fVScale = fMinScale;
219 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f); 219 }
220 break; 220 }
221 case 1: 221 }
222 if (fPlateWidth < fImageWidth) 222
223 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f ); 223 void CPWL_Icon::GetImageOffset(FX_FLOAT& x, FX_FLOAT& y) {
224 if (fPlateHeight < fImageHeight) 224 FX_FLOAT fLeft, fBottom;
225 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1. 0f); 225
226 break; 226 this->GetIconPosition(fLeft, fBottom);
227 case 2: 227 x = 0.0f;
228 if (fPlateWidth > fImageWidth) 228 y = 0.0f;
229 fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f ); 229
230 if (fPlateHeight > fImageHeight) 230 FX_FLOAT fImageWidth, fImageHeight;
231 fVScale = fPlateHeight / PWL_MAX(fImageHeight,1. 0f); 231 GetImageSize(fImageWidth, fImageHeight);
232 break; 232
233 case 3: 233 FX_FLOAT fHScale, fVScale;
234 break; 234 GetScale(fHScale, fVScale);
235 } 235
236 236 FX_FLOAT fImageFactWidth = fImageWidth * fHScale;
237 FX_FLOAT fMinScale; 237 FX_FLOAT fImageFactHeight = fImageHeight * fVScale;
238 if (IsProportionalScale()) 238
239 { 239 FX_FLOAT fPlateWidth, fPlateHeight;
240 fMinScale = PWL_MIN(fHScale,fVScale); 240 CPDF_Rect rcPlate = this->GetClientRect();
241 fHScale = fMinScale; 241 fPlateWidth = rcPlate.right - rcPlate.left;
242 fVScale = fMinScale; 242 fPlateHeight = rcPlate.top - rcPlate.bottom;
243 } 243
244 } 244 x = (fPlateWidth - fImageFactWidth) * fLeft;
245 } 245 y = (fPlateHeight - fImageFactHeight) * fBottom;
246 246 }
247 void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
248 {
249 FX_FLOAT fLeft,fBottom;
250
251 this->GetIconPosition(fLeft,fBottom);
252 x = 0.0f;
253 y = 0.0f;
254
255 FX_FLOAT fImageWidth,fImageHeight;
256 GetImageSize(fImageWidth,fImageHeight);
257
258 FX_FLOAT fHScale,fVScale;
259 GetScale(fHScale,fVScale);
260
261 FX_FLOAT fImageFactWidth = fImageWidth * fHScale;
262 FX_FLOAT fImageFactHeight = fImageHeight * fVScale;
263
264 FX_FLOAT fPlateWidth,fPlateHeight;
265 CPDF_Rect rcPlate = this->GetClientRect();
266 fPlateWidth = rcPlate.right - rcPlate.left;
267 fPlateHeight = rcPlate.top - rcPlate.bottom;
268
269 x = (fPlateWidth - fImageFactWidth) * fLeft;
270 y = (fPlateHeight - fImageFactHeight) * fBottom;
271 }
272
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698