page_orientation.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "pdf/page_orientation.h"
  5. #include <type_traits>
  6. namespace chrome_pdf {
  7. namespace {
  8. // Adds two PageOrientation values together. This works because the underlying
  9. // integer values have been chosen to allow modular arithmetic.
  10. PageOrientation AddOrientations(PageOrientation first, PageOrientation second) {
  11. using IntType = std::underlying_type<PageOrientation>::type;
  12. constexpr auto kOrientationCount =
  13. static_cast<IntType>(PageOrientation::kLast) + 1;
  14. auto first_int = static_cast<IntType>(first);
  15. auto second_int = static_cast<IntType>(second);
  16. return static_cast<PageOrientation>((first_int + second_int) %
  17. kOrientationCount);
  18. }
  19. } // namespace
  20. PageOrientation RotateClockwise(PageOrientation orientation) {
  21. return AddOrientations(orientation, PageOrientation::kClockwise90);
  22. }
  23. PageOrientation RotateCounterclockwise(PageOrientation orientation) {
  24. // Adding `kLast` is equivalent to rotating one step counterclockwise.
  25. return AddOrientations(orientation, PageOrientation::kLast);
  26. }
  27. } // namespace chrome_pdf