Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / source / rtftok / rtffly.hxx
blobb1dec0c77b4f40b01926f403a10c7f110dbe1785
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <com/sun/star/text/HoriOrientation.hpp>
13 #include <com/sun/star/text/RelOrientation.hpp>
14 #include <com/sun/star/text/VertOrientation.hpp>
16 #include <ooxml/resourceids.hxx>
17 #include <osl/endian.h>
19 namespace writerfilter::rtftok
21 /// Stores the vertical orientation properties of an RTF fly frame.
22 class RTFVertOrient
24 public:
25 explicit RTFVertOrient(sal_uInt16 nValue)
26 : m_nVal(nValue)
30 sal_uInt16 GetOrient() const { return OSL_LONIBBLE(OSL_LOBYTE(m_nVal)); }
32 sal_uInt16 GetRelation() const { return OSL_HINIBBLE(OSL_LOBYTE(m_nVal)); }
34 sal_Int32 GetAlign() const
36 sal_Int32 nAlign = 0;
37 switch (GetOrient())
39 case css::text::VertOrientation::CENTER:
40 nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_center;
41 break;
42 case css::text::VertOrientation::TOP:
43 nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_top;
44 break;
45 case css::text::VertOrientation::BOTTOM:
46 nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_bottom;
47 break;
50 return nAlign;
53 sal_Int32 GetAnchor() const
55 sal_Int32 nAnchor = 0;
56 switch (GetRelation())
58 case css::text::RelOrientation::FRAME:
59 nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_text;
60 break;
61 case css::text::RelOrientation::PAGE_FRAME:
62 nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_page;
63 break;
64 case css::text::RelOrientation::PAGE_PRINT_AREA:
65 nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_margin;
66 break;
69 return nAnchor;
72 private:
73 sal_uInt16 m_nVal;
76 /// Stores the horizontal orientation properties of an RTF fly frame.
77 class RTFHoriOrient
79 public:
80 explicit RTFHoriOrient(sal_uInt16 nValue)
81 : m_nVal(nValue)
85 sal_uInt16 GetOrient() const { return OSL_LONIBBLE(OSL_LOBYTE(m_nVal)); }
87 sal_uInt16 GetRelation() const { return OSL_LONIBBLE(OSL_HIBYTE(m_nVal)); }
89 sal_Int32 GetAlign() const
91 sal_Int32 nAlign = 0;
92 switch (GetOrient())
94 case css::text::HoriOrientation::CENTER:
95 nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_center;
96 break;
97 case css::text::HoriOrientation::RIGHT:
98 nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_right;
99 break;
100 case css::text::HoriOrientation::LEFT:
101 nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_left;
102 break;
103 case css::text::HoriOrientation::INSIDE:
104 nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_inside;
105 break;
106 case css::text::HoriOrientation::OUTSIDE:
107 nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_outside;
108 break;
111 return nAlign;
114 sal_Int32 GetAnchor() const
116 sal_Int32 nAnchor = 0;
117 switch (GetRelation())
119 case css::text::RelOrientation::FRAME:
120 nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_text;
121 break;
122 case css::text::RelOrientation::PAGE_FRAME:
123 nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_page;
124 break;
125 case css::text::RelOrientation::PAGE_PRINT_AREA:
126 nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_margin;
127 break;
130 return nAnchor;
133 private:
134 sal_uInt16 m_nVal;
136 } // namespace writerfilter::rtftok
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */