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/fxfa/include/xfa_ffwidget.h" | 7 #include "xfa/fxfa/include/xfa_ffwidget.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 void CXFA_FFWidget::Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy) { | 261 void CXFA_FFWidget::Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy) { |
262 CFX_Matrix mt; | 262 CFX_Matrix mt; |
263 GetRotateMatrix(mt); | 263 GetRotateMatrix(mt); |
264 if (mt.IsIdentity()) { | 264 if (mt.IsIdentity()) { |
265 return; | 265 return; |
266 } | 266 } |
267 CFX_Matrix mtReverse; | 267 CFX_Matrix mtReverse; |
268 mtReverse.SetReverse(mt); | 268 mtReverse.SetReverse(mt); |
269 mtReverse.TransformPoint(fx, fy); | 269 mtReverse.TransformPoint(fx, fy); |
270 } | 270 } |
271 static void XFA_GetMatrix(CFX_Matrix& m, | 271 static void XFA_GetMatrix(CFX_Matrix& m, |
Lei Zhang
2016/05/20 03:48:02
BTW, this only has 1 caller and |at| is always XFA
Wei Li
2016/05/20 16:33:15
Yes, I noticed that. I suspect there are some unfi
| |
272 int32_t iRotate, | 272 int32_t iRotate, |
273 int32_t at, | 273 XFA_ATTRIBUTEENUM at, |
274 const CFX_RectF& rt) { | 274 const CFX_RectF& rt) { |
275 if (!iRotate) { | 275 if (!iRotate) { |
276 return; | 276 return; |
277 } | 277 } |
278 FX_FLOAT fAnchorX, fAnchorY; | 278 FX_FLOAT fAnchorX = 0, fAnchorY = 0; |
Lei Zhang
2016/05/20 03:48:02
One per line please.
Wei Li
2016/05/20 16:33:14
Done.
| |
279 switch (at) { | 279 switch (at) { |
280 case XFA_ATTRIBUTEENUM_TopLeft: | 280 case XFA_ATTRIBUTEENUM_TopLeft: |
281 fAnchorX = rt.left, fAnchorY = rt.top; | 281 fAnchorX = rt.left, fAnchorY = rt.top; |
282 break; | 282 break; |
283 case XFA_ATTRIBUTEENUM_TopCenter: | 283 case XFA_ATTRIBUTEENUM_TopCenter: |
284 fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.top; | 284 fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.top; |
285 break; | 285 break; |
286 case XFA_ATTRIBUTEENUM_TopRight: | 286 case XFA_ATTRIBUTEENUM_TopRight: |
287 fAnchorX = rt.right(), fAnchorY = rt.top; | 287 fAnchorX = rt.right(), fAnchorY = rt.top; |
288 break; | 288 break; |
289 case XFA_ATTRIBUTEENUM_MiddleLeft: | 289 case XFA_ATTRIBUTEENUM_MiddleLeft: |
290 fAnchorX = rt.left, fAnchorY = (rt.top + rt.bottom()) / 2; | 290 fAnchorX = rt.left, fAnchorY = (rt.top + rt.bottom()) / 2; |
291 break; | 291 break; |
292 case XFA_ATTRIBUTEENUM_MiddleCenter: | 292 case XFA_ATTRIBUTEENUM_MiddleCenter: |
293 fAnchorX = (rt.left + rt.right()) / 2, | 293 fAnchorX = (rt.left + rt.right()) / 2, |
294 fAnchorY = (rt.top + rt.bottom()) / 2; | 294 fAnchorY = (rt.top + rt.bottom()) / 2; |
295 break; | 295 break; |
296 case XFA_ATTRIBUTEENUM_MiddleRight: | 296 case XFA_ATTRIBUTEENUM_MiddleRight: |
297 fAnchorX = rt.right(), fAnchorY = (rt.top + rt.bottom()) / 2; | 297 fAnchorX = rt.right(), fAnchorY = (rt.top + rt.bottom()) / 2; |
298 break; | 298 break; |
299 case XFA_ATTRIBUTEENUM_BottomLeft: | 299 case XFA_ATTRIBUTEENUM_BottomLeft: |
300 fAnchorX = rt.left, fAnchorY = rt.bottom(); | 300 fAnchorX = rt.left, fAnchorY = rt.bottom(); |
301 break; | 301 break; |
302 case XFA_ATTRIBUTEENUM_BottomCenter: | 302 case XFA_ATTRIBUTEENUM_BottomCenter: |
303 fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.bottom(); | 303 fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.bottom(); |
304 break; | 304 break; |
305 case XFA_ATTRIBUTEENUM_BottomRight: | 305 case XFA_ATTRIBUTEENUM_BottomRight: |
306 fAnchorX = rt.right(), fAnchorY = rt.bottom(); | 306 fAnchorX = rt.right(), fAnchorY = rt.bottom(); |
307 break; | 307 break; |
308 default: | |
309 break; | |
308 } | 310 } |
309 switch (iRotate) { | 311 switch (iRotate) { |
310 case 90: | 312 case 90: |
311 m.a = 0, m.b = -1, m.c = 1, m.d = 0, m.e = fAnchorX - fAnchorY, | 313 m.a = 0, m.b = -1, m.c = 1, m.d = 0, m.e = fAnchorX - fAnchorY, |
312 m.f = fAnchorX + fAnchorY; | 314 m.f = fAnchorX + fAnchorY; |
313 break; | 315 break; |
314 case 180: | 316 case 180: |
315 m.a = -1, m.b = 0, m.c = 0, m.d = -1, m.e = fAnchorX * 2, | 317 m.a = -1, m.b = 0, m.c = 0, m.d = -1, m.e = fAnchorX * 2, |
316 m.f = fAnchorY * 2; | 318 m.f = fAnchorY * 2; |
317 break; | 319 break; |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 startAngle, sweepAngle); | 1152 startAngle, sweepAngle); |
1151 } | 1153 } |
1152 static void XFA_BOX_GetPath(CXFA_Box box, | 1154 static void XFA_BOX_GetPath(CXFA_Box box, |
1153 const CXFA_StrokeArray& strokes, | 1155 const CXFA_StrokeArray& strokes, |
1154 CFX_RectF rtWidget, | 1156 CFX_RectF rtWidget, |
1155 CFX_Path& path, | 1157 CFX_Path& path, |
1156 int32_t nIndex, | 1158 int32_t nIndex, |
1157 FX_BOOL bStart, | 1159 FX_BOOL bStart, |
1158 FX_BOOL bCorner) { | 1160 FX_BOOL bCorner) { |
1159 ASSERT(nIndex >= 0 && nIndex < 8); | 1161 ASSERT(nIndex >= 0 && nIndex < 8); |
1160 FX_BOOL bInverted, bRound; | 1162 FX_FLOAT sx = 0.0f; |
Lei Zhang
2016/05/20 03:48:02
Can you declare variables closer to where they are
Wei Li
2016/05/20 16:33:15
Done.
| |
1161 FX_FLOAT fRadius1, fRadius2, sx, sy, vx, vy, nx, ny, offsetY, offsetX, | 1163 FX_FLOAT sy = 0.0f; |
1162 offsetEX, offsetEY; | 1164 FX_FLOAT vx = 1.0f; |
1163 CFX_PointF cpStart, cp, cp1, cp2; | 1165 FX_FLOAT vy = 1.0f; |
1164 CFX_RectF rtRadius; | 1166 FX_FLOAT nx = 1.0f; |
1167 FX_FLOAT ny = 1.0f; | |
1168 CFX_PointF cpStart; | |
1169 CFX_PointF cp1; | |
1170 CFX_PointF cp2; | |
1165 int32_t n = (nIndex & 1) ? nIndex - 1 : nIndex; | 1171 int32_t n = (nIndex & 1) ? nIndex - 1 : nIndex; |
1166 CXFA_Corner corner1(strokes[n].GetNode()); | 1172 CXFA_Corner corner1(strokes[n].GetNode()); |
1167 CXFA_Corner corner2(strokes[(n + 2) % 8].GetNode()); | 1173 CXFA_Corner corner2(strokes[(n + 2) % 8].GetNode()); |
1168 fRadius1 = bCorner ? corner1.GetRadius() : 0; | 1174 FX_FLOAT fRadius1 = bCorner ? corner1.GetRadius() : 0.0f; |
1169 fRadius2 = bCorner ? corner2.GetRadius() : 0; | 1175 FX_FLOAT fRadius2 = bCorner ? corner2.GetRadius() : 0.0f; |
1170 bInverted = corner1.IsInverted(); | 1176 FX_BOOL bInverted = corner1.IsInverted(); |
1171 offsetY = 0.0f; | 1177 FX_FLOAT offsetY = 0.0f; |
1172 offsetX = 0.0f; | 1178 FX_FLOAT offsetX = 0.0f; |
1173 bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; | 1179 FX_BOOL bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; |
1174 FX_FLOAT halfAfter = 0.0f; | 1180 FX_FLOAT halfAfter = 0.0f; |
1175 FX_FLOAT halfBefore = 0.0f; | 1181 FX_FLOAT halfBefore = 0.0f; |
1176 CXFA_Stroke stroke = strokes[nIndex]; | 1182 CXFA_Stroke stroke = strokes[nIndex]; |
1177 if (stroke.IsCorner()) { | 1183 if (stroke.IsCorner()) { |
1178 CXFA_Stroke edgeBefore = strokes[(nIndex + 1 * 8 - 1) % 8]; | 1184 CXFA_Stroke edgeBefore = strokes[(nIndex + 1 * 8 - 1) % 8]; |
1179 CXFA_Stroke edgeAfter = strokes[nIndex + 1]; | 1185 CXFA_Stroke edgeAfter = strokes[nIndex + 1]; |
1180 if (stroke.IsInverted()) { | 1186 if (stroke.IsInverted()) { |
1181 if (!stroke.SameStyles(edgeBefore)) { | 1187 if (!stroke.SameStyles(edgeBefore)) { |
1182 halfBefore = edgeBefore.GetThickness() / 2; | 1188 halfBefore = edgeBefore.GetThickness() / 2; |
1183 } | 1189 } |
1184 if (!stroke.SameStyles(edgeAfter)) { | 1190 if (!stroke.SameStyles(edgeAfter)) { |
1185 halfAfter = edgeAfter.GetThickness() / 2; | 1191 halfAfter = edgeAfter.GetThickness() / 2; |
1186 } | 1192 } |
1187 } | 1193 } |
1188 } else { | 1194 } else { |
1189 CXFA_Stroke edgeBefore = strokes[(nIndex + 8 - 2) % 8]; | 1195 CXFA_Stroke edgeBefore = strokes[(nIndex + 8 - 2) % 8]; |
1190 CXFA_Stroke edgeAfter = strokes[(nIndex + 2) % 8]; | 1196 CXFA_Stroke edgeAfter = strokes[(nIndex + 2) % 8]; |
1191 if (!bRound && !bInverted) { | 1197 if (!bRound && !bInverted) { |
1192 { halfBefore = edgeBefore.GetThickness() / 2; } | 1198 { halfBefore = edgeBefore.GetThickness() / 2; } |
Lei Zhang
2016/05/20 03:48:02
There's some extra braces here.
Wei Li
2016/05/20 16:33:15
Done.
| |
1193 { halfAfter = edgeAfter.GetThickness() / 2; } | 1199 { halfAfter = edgeAfter.GetThickness() / 2; } |
1194 } | 1200 } |
1195 } | 1201 } |
1196 offsetEX = 0.0f; | 1202 FX_FLOAT offsetEX = 0.0f; |
1197 offsetEY = 0.0f; | 1203 FX_FLOAT offsetEY = 0.0f; |
1198 if (bRound) { | 1204 if (bRound) { |
1199 sy = FX_PI / 2; | 1205 sy = FX_PI / 2; |
1200 } | 1206 } |
1201 switch (nIndex) { | 1207 switch (nIndex) { |
1202 case 0: | 1208 case 0: |
1203 case 1: | 1209 case 1: |
1204 cp1 = rtWidget.TopLeft(); | 1210 cp1 = rtWidget.TopLeft(); |
1205 cp2 = rtWidget.TopRight(); | 1211 cp2 = rtWidget.TopRight(); |
1206 if (nIndex == 0) { | 1212 if (nIndex == 0) { |
1207 cpStart.x = cp1.x - halfBefore; | 1213 cpStart.x = cp1.x - halfBefore; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1284 cp2.y + fRadius2 * ny + offsetEY); | 1290 cp2.y + fRadius2 * ny + offsetEY); |
1285 return; | 1291 return; |
1286 } | 1292 } |
1287 if (bRound) { | 1293 if (bRound) { |
1288 if (fRadius1 < 0) { | 1294 if (fRadius1 < 0) { |
1289 sx -= FX_PI; | 1295 sx -= FX_PI; |
1290 } | 1296 } |
1291 if (bInverted) { | 1297 if (bInverted) { |
1292 sy *= -1; | 1298 sy *= -1; |
1293 } | 1299 } |
1300 CFX_RectF rtRadius; | |
1294 rtRadius.Set(cp1.x + offsetX * 2, cp1.y + offsetY * 2, | 1301 rtRadius.Set(cp1.x + offsetX * 2, cp1.y + offsetY * 2, |
1295 fRadius1 * 2 * vx - offsetX * 2, | 1302 fRadius1 * 2 * vx - offsetX * 2, |
1296 fRadius1 * 2 * vy - offsetY * 2); | 1303 fRadius1 * 2 * vy - offsetY * 2); |
1297 rtRadius.Normalize(); | 1304 rtRadius.Normalize(); |
1298 if (bInverted) { | 1305 if (bInverted) { |
1299 rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); | 1306 rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); |
1300 } | 1307 } |
1301 path.ArcTo(rtRadius.left, rtRadius.top, rtRadius.width, rtRadius.height, sx, | 1308 path.ArcTo(rtRadius.left, rtRadius.top, rtRadius.width, rtRadius.height, sx, |
1302 sy); | 1309 sy); |
1303 } else { | 1310 } else { |
1311 CFX_PointF cp; | |
1304 if (bInverted) { | 1312 if (bInverted) { |
1305 cp.x = cp1.x + fRadius1 * vx, cp.y = cp1.y + fRadius1 * vy; | 1313 cp.x = cp1.x + fRadius1 * vx, cp.y = cp1.y + fRadius1 * vy; |
1306 } else { | 1314 } else { |
1307 cp = cp1; | 1315 cp = cp1; |
1308 } | 1316 } |
1309 path.LineTo(cp.x, cp.y); | 1317 path.LineTo(cp.x, cp.y); |
1310 path.LineTo(cp1.x + fRadius1 * sx + offsetX, | 1318 path.LineTo(cp1.x + fRadius1 * sx + offsetX, |
1311 cp1.y + fRadius1 * sy + offsetY); | 1319 cp1.y + fRadius1 * sy + offsetY); |
1312 } | 1320 } |
1313 } | 1321 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 if (stroke1.GetJoinType() != XFA_ATTRIBUTEENUM_Square) { | 1370 if (stroke1.GetJoinType() != XFA_ATTRIBUTEENUM_Square) { |
1363 bSameStyles = FALSE; | 1371 bSameStyles = FALSE; |
1364 } | 1372 } |
1365 } | 1373 } |
1366 } | 1374 } |
1367 if (bSameStyles) { | 1375 if (bSameStyles) { |
1368 fillPath.AddRectangle(rtWidget.left, rtWidget.top, rtWidget.width, | 1376 fillPath.AddRectangle(rtWidget.left, rtWidget.top, rtWidget.width, |
1369 rtWidget.height); | 1377 rtWidget.height); |
1370 return; | 1378 return; |
1371 } | 1379 } |
1372 FX_BOOL bInverted, bRound; | 1380 |
1373 FX_FLOAT fRadius1, fRadius2, sx, sy, vx, vy, nx, ny; | |
1374 CFX_PointF cp, cp1, cp2; | |
1375 CFX_RectF rtRadius; | |
1376 for (int32_t i = 0; i < 8; i += 2) { | 1381 for (int32_t i = 0; i < 8; i += 2) { |
1382 FX_FLOAT sx = 0.0f; | |
1383 FX_FLOAT sy = 0.0f; | |
1384 FX_FLOAT vx = 1.0f; | |
1385 FX_FLOAT vy = 1.0f; | |
1386 FX_FLOAT nx = 1.0f; | |
1387 FX_FLOAT ny = 1.0f; | |
1388 CFX_PointF cp1, cp2; | |
1377 CXFA_Corner corner1(strokes[i].GetNode()); | 1389 CXFA_Corner corner1(strokes[i].GetNode()); |
1378 CXFA_Corner corner2(strokes[(i + 2) % 8].GetNode()); | 1390 CXFA_Corner corner2(strokes[(i + 2) % 8].GetNode()); |
1379 fRadius1 = corner1.GetRadius(); | 1391 FX_FLOAT fRadius1 = corner1.GetRadius(); |
1380 fRadius2 = corner2.GetRadius(); | 1392 FX_FLOAT fRadius2 = corner2.GetRadius(); |
1381 bInverted = corner1.IsInverted(); | 1393 FX_BOOL bInverted = corner1.IsInverted(); |
1382 bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; | 1394 FX_BOOL bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; |
1383 if (bRound) { | 1395 if (bRound) { |
1384 sy = FX_PI / 2; | 1396 sy = FX_PI / 2; |
1385 } | 1397 } |
1386 switch (i) { | 1398 switch (i) { |
1387 case 0: | 1399 case 0: |
1388 cp1 = rtWidget.TopLeft(); | 1400 cp1 = rtWidget.TopLeft(); |
1389 cp2 = rtWidget.TopRight(); | 1401 cp2 = rtWidget.TopRight(); |
1390 vx = 1, vy = 1; | 1402 vx = 1, vy = 1; |
1391 nx = -1, ny = 0; | 1403 nx = -1, ny = 0; |
1392 if (bRound) { | 1404 if (bRound) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 if (i == 0) { | 1444 if (i == 0) { |
1433 fillPath.MoveTo(cp1.x, cp1.y + fRadius1); | 1445 fillPath.MoveTo(cp1.x, cp1.y + fRadius1); |
1434 } | 1446 } |
1435 if (bRound) { | 1447 if (bRound) { |
1436 if (fRadius1 < 0) { | 1448 if (fRadius1 < 0) { |
1437 sx -= FX_PI; | 1449 sx -= FX_PI; |
1438 } | 1450 } |
1439 if (bInverted) { | 1451 if (bInverted) { |
1440 sy *= -1; | 1452 sy *= -1; |
1441 } | 1453 } |
1454 CFX_RectF rtRadius; | |
1442 rtRadius.Set(cp1.x, cp1.y, fRadius1 * 2 * vx, fRadius1 * 2 * vy); | 1455 rtRadius.Set(cp1.x, cp1.y, fRadius1 * 2 * vx, fRadius1 * 2 * vy); |
1443 rtRadius.Normalize(); | 1456 rtRadius.Normalize(); |
1444 if (bInverted) { | 1457 if (bInverted) { |
1445 rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); | 1458 rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); |
1446 } | 1459 } |
1447 fillPath.ArcTo(rtRadius.left, rtRadius.top, rtRadius.width, | 1460 fillPath.ArcTo(rtRadius.left, rtRadius.top, rtRadius.width, |
1448 rtRadius.height, sx, sy); | 1461 rtRadius.height, sx, sy); |
1449 } else { | 1462 } else { |
1463 CFX_PointF cp; | |
1450 if (bInverted) { | 1464 if (bInverted) { |
1451 cp.x = cp1.x + fRadius1 * vx, cp.y = cp1.y + fRadius1 * vy; | 1465 cp.x = cp1.x + fRadius1 * vx, cp.y = cp1.y + fRadius1 * vy; |
1452 } else { | 1466 } else { |
1453 cp = cp1; | 1467 cp = cp1; |
1454 } | 1468 } |
1455 fillPath.LineTo(cp.x, cp.y); | 1469 fillPath.LineTo(cp.x, cp.y); |
1456 fillPath.LineTo(cp1.x + fRadius1 * sx, cp1.y + fRadius1 * sy); | 1470 fillPath.LineTo(cp1.x + fRadius1 * sx, cp1.y + fRadius1 * sy); |
1457 } | 1471 } |
1458 fillPath.LineTo(cp2.x + fRadius2 * nx, cp2.y + fRadius2 * ny); | 1472 fillPath.LineTo(cp2.x + fRadius2 * nx, cp2.y + fRadius2 * ny); |
1459 } | 1473 } |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1961 iType != XFA_ELEMENT_Rectangle) { | 1975 iType != XFA_ELEMENT_Rectangle) { |
1962 return; | 1976 return; |
1963 } | 1977 } |
1964 CXFA_StrokeArray strokes; | 1978 CXFA_StrokeArray strokes; |
1965 if (!(dwFlags & XFA_DRAWBOX_ForceRound) && iType != XFA_ELEMENT_Arc) { | 1979 if (!(dwFlags & XFA_DRAWBOX_ForceRound) && iType != XFA_ELEMENT_Arc) { |
1966 box.GetStrokes(strokes); | 1980 box.GetStrokes(strokes); |
1967 } | 1981 } |
1968 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); | 1982 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
1969 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); | 1983 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
1970 } | 1984 } |
OLD | NEW |