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 "fpdfsdk/include/pdfwindow/PDFWindow.h" | |
8 #include "fpdfsdk/include/pdfwindow/PWL_Icon.h" | 7 #include "fpdfsdk/include/pdfwindow/PWL_Icon.h" |
9 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h" | 8 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h" |
10 #include "fpdfsdk/include/pdfwindow/PWL_Wnd.h" | 9 #include "fpdfsdk/include/pdfwindow/PWL_Wnd.h" |
11 | 10 |
12 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | 11 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
13 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | 12 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
14 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | 13 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
15 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) | 14 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
16 | 15 |
17 /* ---------------------------- CPWL_Utils ------------------------------ */ | |
18 | |
19 CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, | 16 CFX_ByteString CPWL_Utils::GetAppStreamFromArray(const CPWL_PathData* pPathData, |
20 int32_t nCount) { | 17 int32_t nCount) { |
21 CFX_ByteTextBuf csAP; | 18 CFX_ByteTextBuf csAP; |
22 | 19 |
23 for (int32_t i = 0; i < nCount; i++) { | 20 for (int32_t i = 0; i < nCount; i++) { |
24 switch (pPathData[i].type) { | 21 switch (pPathData[i].type) { |
25 case PWLPT_MOVETO: | 22 case PWLPT_MOVETO: |
26 csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " m\n"; | 23 csAP << pPathData[i].point.x << " " << pPathData[i].point.y << " m\n"; |
27 break; | 24 break; |
28 case PWLPT_LINETO: | 25 case PWLPT_LINETO: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { | 126 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
130 wrRet.EndPos = wr1.EndPos; | 127 wrRet.EndPos = wr1.EndPos; |
131 } else { | 128 } else { |
132 wrRet.EndPos = wr2.EndPos; | 129 wrRet.EndPos = wr2.EndPos; |
133 } | 130 } |
134 | 131 |
135 return wrRet; | 132 return wrRet; |
136 } | 133 } |
137 | 134 |
138 CFX_ByteString CPWL_Utils::GetAP_Check(const CPDF_Rect& crBBox) { | 135 CFX_ByteString CPWL_Utils::GetAP_Check(const CPDF_Rect& crBBox) { |
139 CFX_ByteTextBuf csAP; | 136 const FX_FLOAT fWidth = crBBox.right - crBBox.left; |
| 137 const FX_FLOAT fHeight = crBBox.top - crBBox.bottom; |
140 | 138 |
141 FX_FLOAT fWidth = crBBox.right - crBBox.left; | 139 CPWL_Point pts[8][3] = {{CPWL_Point(0.28f, 0.52f), CPWL_Point(0.27f, 0.48f), |
142 FX_FLOAT fHeight = crBBox.top - crBBox.bottom; | 140 CPWL_Point(0.29f, 0.40f)}, |
| 141 {CPWL_Point(0.30f, 0.33f), CPWL_Point(0.31f, 0.29f), |
| 142 CPWL_Point(0.31f, 0.28f)}, |
| 143 {CPWL_Point(0.39f, 0.28f), CPWL_Point(0.49f, 0.29f), |
| 144 CPWL_Point(0.77f, 0.67f)}, |
| 145 {CPWL_Point(0.76f, 0.68f), CPWL_Point(0.78f, 0.69f), |
| 146 CPWL_Point(0.76f, 0.75f)}, |
| 147 {CPWL_Point(0.76f, 0.75f), CPWL_Point(0.73f, 0.80f), |
| 148 CPWL_Point(0.68f, 0.75f)}, |
| 149 {CPWL_Point(0.68f, 0.74f), CPWL_Point(0.68f, 0.74f), |
| 150 CPWL_Point(0.44f, 0.47f)}, |
| 151 {CPWL_Point(0.43f, 0.47f), CPWL_Point(0.40f, 0.47f), |
| 152 CPWL_Point(0.41f, 0.58f)}, |
| 153 {CPWL_Point(0.40f, 0.60f), CPWL_Point(0.28f, 0.66f), |
| 154 CPWL_Point(0.30f, 0.56f)}}; |
143 | 155 |
144 const int32_t num = 8; | 156 for (size_t i = 0; i < FX_ArraySize(pts); ++i) { |
145 | 157 for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { |
146 CPWL_Point pts[num * 3] = {// 1 | 158 pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; |
147 CPWL_Point(0.28f, 0.52f), CPWL_Point(0.27f, 0.48f), | 159 pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; |
148 CPWL_Point(0.29f, 0.40f), | 160 } |
149 | |
150 // 2 | |
151 CPWL_Point(0.30f, 0.33f), CPWL_Point(0.31f, 0.29f), | |
152 CPWL_Point(0.31f, 0.28f), | |
153 | |
154 // 3 | |
155 CPWL_Point(0.39f, 0.28f), CPWL_Point(0.49f, 0.29f), | |
156 CPWL_Point(0.77f, 0.67f), | |
157 | |
158 // 4 | |
159 CPWL_Point(0.76f, 0.68f), CPWL_Point(0.78f, 0.69f), | |
160 CPWL_Point(0.76f, 0.75f), | |
161 | |
162 // 5 | |
163 CPWL_Point(0.76f, 0.75f), CPWL_Point(0.73f, 0.80f), | |
164 CPWL_Point(0.68f, 0.75f), | |
165 | |
166 // 6 | |
167 CPWL_Point(0.68f, 0.74f), CPWL_Point(0.68f, 0.74f), | |
168 CPWL_Point(0.44f, 0.47f), | |
169 | |
170 // 7 | |
171 CPWL_Point(0.43f, 0.47f), CPWL_Point(0.40f, 0.47f), | |
172 CPWL_Point(0.41f, 0.58f), | |
173 | |
174 // 8 | |
175 CPWL_Point(0.40f, 0.60f), CPWL_Point(0.28f, 0.66f), | |
176 CPWL_Point(0.30f, 0.56f)}; | |
177 | |
178 for (int32_t j = 0; j < num * 3; j++) { | |
179 pts[j].x *= fWidth; | |
180 pts[j].x += crBBox.left; | |
181 | |
182 pts[j].y *= fHeight; | |
183 pts[j].y += crBBox.bottom; | |
184 } | 161 } |
185 | 162 |
186 csAP << pts[0].x << " " << pts[0].y << " m\n"; | 163 CFX_ByteTextBuf csAP; |
| 164 csAP << pts[0][0].x << " " << pts[0][0].y << " m\n"; |
187 | 165 |
188 for (int32_t i = 0; i < num; i++) { | 166 for (size_t i = 0; i < FX_ArraySize(pts); ++i) { |
189 int32_t nCur = i * 3; | 167 size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; |
190 int32_t n1 = i * 3 + 1; | |
191 int32_t n2 = i * 3 + 2; | |
192 int32_t nNext = (i < num - 1 ? (i + 1) * 3 : 0); | |
193 | 168 |
194 FX_FLOAT px1 = pts[n1].x - pts[nCur].x; | 169 FX_FLOAT px1 = pts[i][1].x - pts[i][0].x; |
195 FX_FLOAT py1 = pts[n1].y - pts[nCur].y; | 170 FX_FLOAT py1 = pts[i][1].y - pts[i][0].y; |
196 FX_FLOAT px2 = pts[n2].x - pts[nNext].x; | 171 FX_FLOAT px2 = pts[i][2].x - pts[nNext][0].x; |
197 FX_FLOAT py2 = pts[n2].y - pts[nNext].y; | 172 FX_FLOAT py2 = pts[i][2].y - pts[nNext][0].y; |
198 | 173 |
199 csAP << pts[nCur].x + px1 * PWL_BEZIER << " " | 174 csAP << pts[i][0].x + px1 * PWL_BEZIER << " " |
200 << pts[nCur].y + py1 * PWL_BEZIER << " " | 175 << pts[i][0].y + py1 * PWL_BEZIER << " " |
201 << pts[nNext].x + px2 * PWL_BEZIER << " " | 176 << pts[nNext][0].x + px2 * PWL_BEZIER << " " |
202 << pts[nNext].y + py2 * PWL_BEZIER << " " << pts[nNext].x << " " | 177 << pts[nNext][0].y + py2 * PWL_BEZIER << " " << pts[nNext][0].x << " " |
203 << pts[nNext].y << " c\n"; | 178 << pts[nNext][0].y << " c\n"; |
204 } | 179 } |
205 | 180 |
206 return csAP.GetByteString(); | 181 return csAP.GetByteString(); |
207 } | 182 } |
208 | 183 |
209 CFX_ByteString CPWL_Utils::GetAP_Circle(const CPDF_Rect& crBBox) { | 184 CFX_ByteString CPWL_Utils::GetAP_Circle(const CPDF_Rect& crBBox) { |
210 CFX_ByteTextBuf csAP; | 185 CFX_ByteTextBuf csAP; |
211 | 186 |
212 FX_FLOAT fWidth = crBBox.right - crBBox.left; | 187 FX_FLOAT fWidth = crBBox.right - crBBox.left; |
213 FX_FLOAT fHeight = crBBox.top - crBBox.bottom; | 188 FX_FLOAT fHeight = crBBox.top - crBBox.bottom; |
(...skipping 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2331 else | 2306 else |
2332 GetPathDataFromArray(path, PathArray, 30); | 2307 GetPathDataFromArray(path, PathArray, 30); |
2333 } | 2308 } |
2334 | 2309 |
2335 void CPWL_Utils::GetGraphics_Cross(CFX_ByteString& sPathData, | 2310 void CPWL_Utils::GetGraphics_Cross(CFX_ByteString& sPathData, |
2336 CFX_PathData& path, | 2311 CFX_PathData& path, |
2337 const CPDF_Rect& crBBox, | 2312 const CPDF_Rect& crBBox, |
2338 const PWL_PATH_TYPE type) { | 2313 const PWL_PATH_TYPE type) { |
2339 FX_FLOAT fWidth = crBBox.right - crBBox.left; | 2314 FX_FLOAT fWidth = crBBox.right - crBBox.left; |
2340 FX_FLOAT fHeight = crBBox.top - crBBox.bottom; | 2315 FX_FLOAT fHeight = crBBox.top - crBBox.bottom; |
2341 // FX_FLOAT fcatercorner = (FX_FLOAT)sqrt(fWidth*fWidth + fHeight*fHeight); | |
2342 CPWL_Point center_point(crBBox.left + fWidth / 2, | 2316 CPWL_Point center_point(crBBox.left + fWidth / 2, |
2343 crBBox.bottom + fHeight / 2); | 2317 crBBox.bottom + fHeight / 2); |
2344 | 2318 |
2345 CPWL_PathData PathArray[] = { | 2319 CPWL_PathData PathArray[] = { |
2346 CPWL_PathData( | 2320 CPWL_PathData( |
2347 CPWL_Point(center_point.x, center_point.y + fHeight / 10.0f), | 2321 CPWL_Point(center_point.x, center_point.y + fHeight / 10.0f), |
2348 PWLPT_MOVETO), | 2322 PWLPT_MOVETO), |
2349 CPWL_PathData( | 2323 CPWL_PathData( |
2350 CPWL_Point(center_point.x + fWidth * 0.3f, | 2324 CPWL_Point(center_point.x + fWidth * 0.3f, |
2351 center_point.y + fHeight / 10.0f + fWidth * 0.3f), | 2325 center_point.y + fHeight / 10.0f + fWidth * 0.3f), |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3701 break; | 3675 break; |
3702 case COLORTYPE_RGB: | 3676 case COLORTYPE_RGB: |
3703 CPWL_Utils::ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4, | 3677 CPWL_Utils::ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4, |
3704 fColor1, fColor2, fColor3); | 3678 fColor1, fColor2, fColor3); |
3705 break; | 3679 break; |
3706 } | 3680 } |
3707 break; | 3681 break; |
3708 } | 3682 } |
3709 nColorType = other_nColorType; | 3683 nColorType = other_nColorType; |
3710 } | 3684 } |
OLD | NEW |