alignment.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. // Copyright (c) 2010-2015 openpyxl
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE
  21. //
  22. // @license: http://www.opensource.org/licenses/mit-license.php
  23. // @author: see AUTHORS file
  24. #include <xlnt/styles/alignment.hpp>
  25. namespace xlnt {
  26. bool alignment::wrap() const
  27. {
  28. return wrap_text_;
  29. }
  30. alignment &alignment::wrap(bool wrap_text)
  31. {
  32. wrap_text_ = wrap_text;
  33. return *this;
  34. }
  35. bool alignment::shrink() const
  36. {
  37. return shrink_to_fit_;
  38. }
  39. alignment &alignment::shrink(bool shrink_to_fit)
  40. {
  41. shrink_to_fit_ = shrink_to_fit;
  42. return *this;
  43. }
  44. optional<horizontal_alignment> alignment::horizontal() const
  45. {
  46. return horizontal_;
  47. }
  48. alignment &alignment::horizontal(horizontal_alignment horizontal)
  49. {
  50. horizontal_ = horizontal;
  51. return *this;
  52. }
  53. optional<vertical_alignment> alignment::vertical() const
  54. {
  55. return vertical_;
  56. }
  57. alignment &alignment::vertical(vertical_alignment vertical)
  58. {
  59. vertical_ = vertical;
  60. return *this;
  61. }
  62. alignment &alignment::indent(int value)
  63. {
  64. indent_ = value;
  65. return *this;
  66. }
  67. optional<int> alignment::indent() const
  68. {
  69. return indent_;
  70. }
  71. alignment &alignment::rotation(int value)
  72. {
  73. text_rotation_ = value;
  74. return *this;
  75. }
  76. optional<int> alignment::rotation() const
  77. {
  78. return text_rotation_;
  79. }
  80. bool alignment::operator==(const alignment &right) const
  81. {
  82. auto &left = *this;
  83. if (left.horizontal().is_set() != right.horizontal().is_set())
  84. {
  85. return false;
  86. }
  87. if (left.horizontal().is_set())
  88. {
  89. if (left.horizontal().get() != right.horizontal().get())
  90. {
  91. return false;
  92. }
  93. }
  94. if (left.indent().is_set() != right.indent().is_set())
  95. {
  96. return false;
  97. }
  98. if (left.indent().is_set())
  99. {
  100. if (left.indent().get() != right.indent().get())
  101. {
  102. return false;
  103. }
  104. }
  105. if (left.rotation().is_set() != right.rotation().is_set())
  106. {
  107. return false;
  108. }
  109. if (left.rotation().is_set())
  110. {
  111. if (left.rotation().get() != right.rotation().get())
  112. {
  113. return false;
  114. }
  115. }
  116. if (left.shrink() != right.shrink())
  117. {
  118. return false;
  119. }
  120. if (left.vertical().is_set() != right.vertical().is_set())
  121. {
  122. return false;
  123. }
  124. if (left.vertical().is_set())
  125. {
  126. if (left.vertical().get() != right.vertical().get())
  127. {
  128. return false;
  129. }
  130. }
  131. if (left.wrap() != right.wrap())
  132. {
  133. return false;
  134. }
  135. return true;
  136. }
  137. bool alignment::operator!=(const alignment &other) const
  138. {
  139. return !(*this == other);
  140. }
  141. } // namespace xlnt