| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "core/fxcrt/fx_coordinates.h" | 9 #include "core/fxcrt/fx_coordinates.h" |
| 10 #include "core/fxcrt/fx_ext.h" | 10 #include "core/fxcrt/fx_ext.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 void FX_RECT::Union(const FX_RECT& other_rect) { | 36 void FX_RECT::Union(const FX_RECT& other_rect) { |
| 37 Normalize(); | 37 Normalize(); |
| 38 FX_RECT other = other_rect; | 38 FX_RECT other = other_rect; |
| 39 other.Normalize(); | 39 other.Normalize(); |
| 40 left = left < other.left ? left : other.left; | 40 left = left < other.left ? left : other.left; |
| 41 right = right > other.right ? right : other.right; | 41 right = right > other.right ? right : other.right; |
| 42 bottom = bottom > other.bottom ? bottom : other.bottom; | 42 bottom = bottom > other.bottom ? bottom : other.bottom; |
| 43 top = top < other.top ? top : other.top; | 43 top = top < other.top ? top : other.top; |
| 44 } | 44 } |
| 45 FX_BOOL GetIntersection(FX_FLOAT low1, | 45 bool GetIntersection(FX_FLOAT low1, |
| 46 FX_FLOAT high1, | 46 FX_FLOAT high1, |
| 47 FX_FLOAT low2, | 47 FX_FLOAT low2, |
| 48 FX_FLOAT high2, | 48 FX_FLOAT high2, |
| 49 FX_FLOAT& interlow, | 49 FX_FLOAT& interlow, |
| 50 FX_FLOAT& interhigh) { | 50 FX_FLOAT& interhigh) { |
| 51 if (low1 >= high2 || low2 >= high1) { | 51 if (low1 >= high2 || low2 >= high1) { |
| 52 return FALSE; | 52 return false; |
| 53 } | 53 } |
| 54 interlow = low1 > low2 ? low1 : low2; | 54 interlow = low1 > low2 ? low1 : low2; |
| 55 interhigh = high1 > high2 ? high2 : high1; | 55 interhigh = high1 > high2 ? high2 : high1; |
| 56 return TRUE; | 56 return true; |
| 57 } | 57 } |
| 58 extern "C" int FXSYS_round(FX_FLOAT d) { | 58 extern "C" int FXSYS_round(FX_FLOAT d) { |
| 59 if (d < (FX_FLOAT)INT_MIN) { | 59 if (d < (FX_FLOAT)INT_MIN) { |
| 60 return INT_MIN; | 60 return INT_MIN; |
| 61 } | 61 } |
| 62 if (d > (FX_FLOAT)INT_MAX) { | 62 if (d > (FX_FLOAT)INT_MAX) { |
| 63 return INT_MAX; | 63 return INT_MAX; |
| 64 } | 64 } |
| 65 | 65 |
| 66 return (int)round(d); | 66 return (int)round(d); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 FX_FLOAT ee = m1.e * m2.a + m1.f * m2.c + m2.e; | 283 FX_FLOAT ee = m1.e * m2.a + m1.f * m2.c + m2.e; |
| 284 FX_FLOAT ff = m1.e * m2.b + m1.f * m2.d + m2.f; | 284 FX_FLOAT ff = m1.e * m2.b + m1.f * m2.d + m2.f; |
| 285 m.a = aa, m.b = bb, m.c = cc, m.d = dd, m.e = ee, m.f = ff; | 285 m.a = aa, m.b = bb, m.c = cc, m.d = dd, m.e = ee, m.f = ff; |
| 286 } | 286 } |
| 287 void CFX_Matrix::Concat(FX_FLOAT a_in, | 287 void CFX_Matrix::Concat(FX_FLOAT a_in, |
| 288 FX_FLOAT b_in, | 288 FX_FLOAT b_in, |
| 289 FX_FLOAT c_in, | 289 FX_FLOAT c_in, |
| 290 FX_FLOAT d_in, | 290 FX_FLOAT d_in, |
| 291 FX_FLOAT e_in, | 291 FX_FLOAT e_in, |
| 292 FX_FLOAT f_in, | 292 FX_FLOAT f_in, |
| 293 FX_BOOL bPrepended) { | 293 bool bPrepended) { |
| 294 CFX_Matrix m; | 294 CFX_Matrix m; |
| 295 m.Set(a_in, b_in, c_in, d_in, e_in, f_in); | 295 m.Set(a_in, b_in, c_in, d_in, e_in, f_in); |
| 296 Concat(m, bPrepended); | 296 Concat(m, bPrepended); |
| 297 } | 297 } |
| 298 void CFX_Matrix::Concat(const CFX_Matrix& m, FX_BOOL bPrepended) { | 298 void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) { |
| 299 if (bPrepended) { | 299 if (bPrepended) { |
| 300 FXCRT_Matrix_Concat(*this, m, *this); | 300 FXCRT_Matrix_Concat(*this, m, *this); |
| 301 } else { | 301 } else { |
| 302 FXCRT_Matrix_Concat(*this, *this, m); | 302 FXCRT_Matrix_Concat(*this, *this, m); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, FX_BOOL bPrepended) { | 305 void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, bool bPrepended) { |
| 306 CFX_Matrix m; | 306 CFX_Matrix m; |
| 307 m.SetReverse(src); | 307 m.SetReverse(src); |
| 308 Concat(m, bPrepended); | 308 Concat(m, bPrepended); |
| 309 } | 309 } |
| 310 FX_BOOL CFX_Matrix::IsInvertible() const { | 310 bool CFX_Matrix::IsInvertible() const { |
| 311 return FXSYS_fabs(a * d - b * c) >= 0.0001f; | 311 return FXSYS_fabs(a * d - b * c) >= 0.0001f; |
| 312 } | 312 } |
| 313 FX_BOOL CFX_Matrix::Is90Rotated() const { | 313 bool CFX_Matrix::Is90Rotated() const { |
| 314 return FXSYS_fabs(a * 1000) < FXSYS_fabs(b) && | 314 return FXSYS_fabs(a * 1000) < FXSYS_fabs(b) && |
| 315 FXSYS_fabs(d * 1000) < FXSYS_fabs(c); | 315 FXSYS_fabs(d * 1000) < FXSYS_fabs(c); |
| 316 } | 316 } |
| 317 FX_BOOL CFX_Matrix::IsScaled() const { | 317 bool CFX_Matrix::IsScaled() const { |
| 318 return FXSYS_fabs(b * 1000) < FXSYS_fabs(a) && | 318 return FXSYS_fabs(b * 1000) < FXSYS_fabs(a) && |
| 319 FXSYS_fabs(c * 1000) < FXSYS_fabs(d); | 319 FXSYS_fabs(c * 1000) < FXSYS_fabs(d); |
| 320 } | 320 } |
| 321 void CFX_Matrix::Translate(FX_FLOAT x, FX_FLOAT y, FX_BOOL bPrepended) { | 321 void CFX_Matrix::Translate(FX_FLOAT x, FX_FLOAT y, bool bPrepended) { |
| 322 if (bPrepended) { | 322 if (bPrepended) { |
| 323 e += x * a + y * c; | 323 e += x * a + y * c; |
| 324 f += y * d + x * b; | 324 f += y * d + x * b; |
| 325 } else { | 325 } else { |
| 326 e += x, f += y; | 326 e += x, f += y; |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 void CFX_Matrix::Scale(FX_FLOAT sx, FX_FLOAT sy, FX_BOOL bPrepended) { | 329 void CFX_Matrix::Scale(FX_FLOAT sx, FX_FLOAT sy, bool bPrepended) { |
| 330 a *= sx, d *= sy; | 330 a *= sx, d *= sy; |
| 331 if (bPrepended) { | 331 if (bPrepended) { |
| 332 b *= sx; | 332 b *= sx; |
| 333 c *= sy; | 333 c *= sy; |
| 334 } else { | 334 } else { |
| 335 b *= sy; | 335 b *= sy; |
| 336 c *= sx; | 336 c *= sx; |
| 337 e *= sx; | 337 e *= sx; |
| 338 f *= sy; | 338 f *= sy; |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 void CFX_Matrix::Rotate(FX_FLOAT fRadian, FX_BOOL bPrepended) { | 341 void CFX_Matrix::Rotate(FX_FLOAT fRadian, bool bPrepended) { |
| 342 FX_FLOAT cosValue = FXSYS_cos(fRadian); | 342 FX_FLOAT cosValue = FXSYS_cos(fRadian); |
| 343 FX_FLOAT sinValue = FXSYS_sin(fRadian); | 343 FX_FLOAT sinValue = FXSYS_sin(fRadian); |
| 344 CFX_Matrix m; | 344 CFX_Matrix m; |
| 345 m.Set(cosValue, sinValue, -sinValue, cosValue, 0, 0); | 345 m.Set(cosValue, sinValue, -sinValue, cosValue, 0, 0); |
| 346 if (bPrepended) { | 346 if (bPrepended) { |
| 347 FXCRT_Matrix_Concat(*this, m, *this); | 347 FXCRT_Matrix_Concat(*this, m, *this); |
| 348 } else { | 348 } else { |
| 349 FXCRT_Matrix_Concat(*this, *this, m); | 349 FXCRT_Matrix_Concat(*this, *this, m); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 void CFX_Matrix::RotateAt(FX_FLOAT fRadian, | 352 void CFX_Matrix::RotateAt(FX_FLOAT fRadian, |
| 353 FX_FLOAT dx, | 353 FX_FLOAT dx, |
| 354 FX_FLOAT dy, | 354 FX_FLOAT dy, |
| 355 FX_BOOL bPrepended) { | 355 bool bPrepended) { |
| 356 Translate(dx, dy, bPrepended); | 356 Translate(dx, dy, bPrepended); |
| 357 Rotate(fRadian, bPrepended); | 357 Rotate(fRadian, bPrepended); |
| 358 Translate(-dx, -dy, bPrepended); | 358 Translate(-dx, -dy, bPrepended); |
| 359 } | 359 } |
| 360 void CFX_Matrix::Shear(FX_FLOAT fAlphaRadian, | 360 void CFX_Matrix::Shear(FX_FLOAT fAlphaRadian, |
| 361 FX_FLOAT fBetaRadian, | 361 FX_FLOAT fBetaRadian, |
| 362 FX_BOOL bPrepended) { | 362 bool bPrepended) { |
| 363 CFX_Matrix m; | 363 CFX_Matrix m; |
| 364 m.Set(1, FXSYS_tan(fAlphaRadian), FXSYS_tan(fBetaRadian), 1, 0, 0); | 364 m.Set(1, FXSYS_tan(fAlphaRadian), FXSYS_tan(fBetaRadian), 1, 0, 0); |
| 365 if (bPrepended) { | 365 if (bPrepended) { |
| 366 FXCRT_Matrix_Concat(*this, m, *this); | 366 FXCRT_Matrix_Concat(*this, m, *this); |
| 367 } else { | 367 } else { |
| 368 FXCRT_Matrix_Concat(*this, *this, m); | 368 FXCRT_Matrix_Concat(*this, *this, m); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 void CFX_Matrix::MatchRect(const CFX_FloatRect& dest, | 371 void CFX_Matrix::MatchRect(const CFX_FloatRect& dest, |
| 372 const CFX_FloatRect& src) { | 372 const CFX_FloatRect& src) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 left = x[i]; | 508 left = x[i]; |
| 509 } | 509 } |
| 510 if (top < y[i]) { | 510 if (top < y[i]) { |
| 511 top = y[i]; | 511 top = y[i]; |
| 512 } | 512 } |
| 513 if (bottom > y[i]) { | 513 if (bottom > y[i]) { |
| 514 bottom = y[i]; | 514 bottom = y[i]; |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 } | 517 } |
| OLD | NEW |