| 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 "core/include/fxcrt/fx_system.h" | 7 #include "core/include/fxcrt/fx_system.h" |
| 8 #include "core/include/fxge/fx_ge.h" | 8 #include "core/include/fxge/fx_ge.h" |
| 9 #include "third_party/base/numerics/safe_math.h" | 9 #include "third_party/base/numerics/safe_math.h" |
| 10 | 10 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 FX_BOOL bEndVert = FXSYS_fabs(middle_x - end_x) < 1.0f / 20; | 257 FX_BOOL bEndVert = FXSYS_fabs(middle_x - end_x) < 1.0f / 20; |
| 258 if (bStartVert && bEndVert) { | 258 if (bStartVert && bEndVert) { |
| 259 int start_dir = middle_y > start_y ? 1 : -1; | 259 int start_dir = middle_y > start_y ? 1 : -1; |
| 260 FX_FLOAT point_y = middle_y + half_width * start_dir; | 260 FX_FLOAT point_y = middle_y + half_width * start_dir; |
| 261 rect.UpdateRect(middle_x + half_width, point_y); | 261 rect.UpdateRect(middle_x + half_width, point_y); |
| 262 rect.UpdateRect(middle_x - half_width, point_y); | 262 rect.UpdateRect(middle_x - half_width, point_y); |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 if (!bStartVert) { | 265 if (!bStartVert) { |
| 266 start_k = FXSYS_Div(middle_y - start_y, middle_x - start_x); | 266 start_k = FXSYS_Div(middle_y - start_y, middle_x - start_x); |
| 267 start_c = middle_y - FXSYS_Mul(start_k, middle_x); | 267 start_c = middle_y - (start_k * middle_x); |
| 268 start_len = FXSYS_sqrt2(start_x - middle_x, start_y - middle_y); | 268 start_len = FXSYS_sqrt2(start_x - middle_x, start_y - middle_y); |
| 269 start_dc = (FX_FLOAT)FXSYS_fabs( | 269 start_dc = (FX_FLOAT)FXSYS_fabs( |
| 270 FXSYS_MulDiv(half_width, start_len, start_x - middle_x)); | 270 FXSYS_MulDiv(half_width, start_len, start_x - middle_x)); |
| 271 } | 271 } |
| 272 if (!bEndVert) { | 272 if (!bEndVert) { |
| 273 end_k = FXSYS_Div(end_y - middle_y, end_x - middle_x); | 273 end_k = FXSYS_Div(end_y - middle_y, end_x - middle_x); |
| 274 end_c = middle_y - FXSYS_Mul(end_k, middle_x); | 274 end_c = middle_y - (end_k * middle_x); |
| 275 end_len = FXSYS_sqrt2(end_x - middle_x, end_y - middle_y); | 275 end_len = FXSYS_sqrt2(end_x - middle_x, end_y - middle_y); |
| 276 end_dc = (FX_FLOAT)FXSYS_fabs( | 276 end_dc = (FX_FLOAT)FXSYS_fabs( |
| 277 FXSYS_MulDiv(half_width, end_len, end_x - middle_x)); | 277 FXSYS_MulDiv(half_width, end_len, end_x - middle_x)); |
| 278 } | 278 } |
| 279 if (bStartVert) { | 279 if (bStartVert) { |
| 280 FX_FLOAT outside_x = start_x; | 280 FX_FLOAT outside_x = start_x; |
| 281 if (end_x < start_x) { | 281 if (end_x < start_x) { |
| 282 outside_x += half_width; | 282 outside_x += half_width; |
| 283 } else { | 283 } else { |
| 284 outside_x -= half_width; | 284 outside_x -= half_width; |
| 285 } | 285 } |
| 286 FX_FLOAT outside_y; | 286 FX_FLOAT outside_y; |
| 287 if (start_y < FXSYS_Mul(end_k, start_x) + end_c) { | 287 if (start_y < (end_k * start_x) + end_c) { |
| 288 outside_y = FXSYS_Mul(end_k, outside_x) + end_c + end_dc; | 288 outside_y = (end_k * outside_x) + end_c + end_dc; |
| 289 } else { | 289 } else { |
| 290 outside_y = FXSYS_Mul(end_k, outside_x) + end_c - end_dc; | 290 outside_y = (end_k * outside_x) + end_c - end_dc; |
| 291 } | 291 } |
| 292 rect.UpdateRect(outside_x, outside_y); | 292 rect.UpdateRect(outside_x, outside_y); |
| 293 return; | 293 return; |
| 294 } | 294 } |
| 295 if (bEndVert) { | 295 if (bEndVert) { |
| 296 FX_FLOAT outside_x = end_x; | 296 FX_FLOAT outside_x = end_x; |
| 297 if (start_x < end_x) { | 297 if (start_x < end_x) { |
| 298 outside_x += half_width; | 298 outside_x += half_width; |
| 299 } else { | 299 } else { |
| 300 outside_x -= half_width; | 300 outside_x -= half_width; |
| 301 } | 301 } |
| 302 FX_FLOAT outside_y; | 302 FX_FLOAT outside_y; |
| 303 if (end_y < FXSYS_Mul(start_k, end_x) + start_c) { | 303 if (end_y < (start_k * end_x) + start_c) { |
| 304 outside_y = FXSYS_Mul(start_k, outside_x) + start_c + start_dc; | 304 outside_y = (start_k * outside_x) + start_c + start_dc; |
| 305 } else { | 305 } else { |
| 306 outside_y = FXSYS_Mul(start_k, outside_x) + start_c - start_dc; | 306 outside_y = (start_k * outside_x) + start_c - start_dc; |
| 307 } | 307 } |
| 308 rect.UpdateRect(outside_x, outside_y); | 308 rect.UpdateRect(outside_x, outside_y); |
| 309 return; | 309 return; |
| 310 } | 310 } |
| 311 if (FXSYS_fabs(start_k - end_k) < 1.0f / 20) { | 311 if (FXSYS_fabs(start_k - end_k) < 1.0f / 20) { |
| 312 int start_dir = middle_x > start_x ? 1 : -1; | 312 int start_dir = middle_x > start_x ? 1 : -1; |
| 313 int end_dir = end_x > middle_x ? 1 : -1; | 313 int end_dir = end_x > middle_x ? 1 : -1; |
| 314 if (start_dir == end_dir) { | 314 if (start_dir == end_dir) { |
| 315 _UpdateLineEndPoints(rect, middle_x, middle_y, end_x, end_y, half_width); | 315 _UpdateLineEndPoints(rect, middle_x, middle_y, end_x, end_y, half_width); |
| 316 } else { | 316 } else { |
| 317 _UpdateLineEndPoints(rect, start_x, start_y, middle_x, middle_y, | 317 _UpdateLineEndPoints(rect, start_x, start_y, middle_x, middle_y, |
| 318 half_width); | 318 half_width); |
| 319 } | 319 } |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 FX_FLOAT start_outside_c = start_c; | 322 FX_FLOAT start_outside_c = start_c; |
| 323 if (end_y < FXSYS_Mul(start_k, end_x) + start_c) { | 323 if (end_y < (start_k * end_x) + start_c) { |
| 324 start_outside_c += start_dc; | 324 start_outside_c += start_dc; |
| 325 } else { | 325 } else { |
| 326 start_outside_c -= start_dc; | 326 start_outside_c -= start_dc; |
| 327 } | 327 } |
| 328 FX_FLOAT end_outside_c = end_c; | 328 FX_FLOAT end_outside_c = end_c; |
| 329 if (start_y < FXSYS_Mul(end_k, start_x) + end_c) { | 329 if (start_y < (end_k * start_x) + end_c) { |
| 330 end_outside_c += end_dc; | 330 end_outside_c += end_dc; |
| 331 } else { | 331 } else { |
| 332 end_outside_c -= end_dc; | 332 end_outside_c -= end_dc; |
| 333 } | 333 } |
| 334 FX_FLOAT join_x = FXSYS_Div(end_outside_c - start_outside_c, start_k - end_k); | 334 FX_FLOAT join_x = FXSYS_Div(end_outside_c - start_outside_c, start_k - end_k); |
| 335 FX_FLOAT join_y = FXSYS_Mul(start_k, join_x) + start_outside_c; | 335 FX_FLOAT join_y = (start_k * join_x) + start_outside_c; |
| 336 rect.UpdateRect(join_x, join_y); | 336 rect.UpdateRect(join_x, join_y); |
| 337 } | 337 } |
| 338 CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width, | 338 CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width, |
| 339 FX_FLOAT miter_limit) const { | 339 FX_FLOAT miter_limit) const { |
| 340 CFX_FloatRect rect(100000 * 1.0f, 100000 * 1.0f, -100000 * 1.0f, | 340 CFX_FloatRect rect(100000 * 1.0f, 100000 * 1.0f, -100000 * 1.0f, |
| 341 -100000 * 1.0f); | 341 -100000 * 1.0f); |
| 342 int iPoint = 0; | 342 int iPoint = 0; |
| 343 FX_FLOAT half_width = line_width; | 343 FX_FLOAT half_width = line_width; |
| 344 int iStartPoint, iEndPoint, iMiddlePoint; | 344 int iStartPoint, iEndPoint, iMiddlePoint; |
| 345 FX_BOOL bJoin; | 345 FX_BOOL bJoin; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 } | 648 } |
| 649 void CFX_GraphStateData::SetDashCount(int count) { | 649 void CFX_GraphStateData::SetDashCount(int count) { |
| 650 FX_Free(m_DashArray); | 650 FX_Free(m_DashArray); |
| 651 m_DashArray = NULL; | 651 m_DashArray = NULL; |
| 652 m_DashCount = count; | 652 m_DashCount = count; |
| 653 if (count == 0) { | 653 if (count == 0) { |
| 654 return; | 654 return; |
| 655 } | 655 } |
| 656 m_DashArray = FX_Alloc(FX_FLOAT, count); | 656 m_DashArray = FX_Alloc(FX_FLOAT, count); |
| 657 } | 657 } |
| OLD | NEW |