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