Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / oox / drawingml / drawingmltypes.hxx
blobfda24edb0f9297d5943b49395dcc8a87dee8e600
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OOX_DRAWINGML_DRAWINGMLTYPES_HXX
21 #define INCLUDED_OOX_DRAWINGML_DRAWINGMLTYPES_HXX
23 #include <memory>
24 #include <optional>
25 #include <string_view>
27 #include <com/sun/star/awt/Point.hpp>
28 #include <com/sun/star/awt/Size.hpp>
29 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
30 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
31 #include <com/sun/star/style/ParagraphAdjust.hpp>
32 #include <com/sun/star/style/TabAlign.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
34 #include <o3tl/unit_conversion.hxx>
35 #include <docmodel/theme/FormatScheme.hxx>
36 #include <oox/dllapi.h>
37 #include <rtl/ustring.hxx>
38 #include <sal/types.h>
40 namespace com::sun::star {
41 namespace drawing { struct Hatch; }
42 namespace xml::sax { class XFastAttributeList; }
45 namespace oox::drawingml {
48 const sal_Int32 PER_PERCENT = 1000;
49 const sal_Int32 MAX_PERCENT = 100 * PER_PERCENT;
51 const sal_Int32 PER_DEGREE = 60000;
52 const sal_Int32 MAX_DEGREE = 360 * PER_DEGREE;
55 struct LineProperties;
56 typedef std::shared_ptr< LineProperties > LinePropertiesPtr;
58 struct FillProperties;
59 typedef std::shared_ptr< FillProperties > FillPropertiesPtr;
61 struct GraphicProperties;
62 typedef std::shared_ptr< GraphicProperties > GraphicPropertiesPtr;
64 struct Shape3DProperties;
65 typedef std::shared_ptr< Shape3DProperties > Shape3DPropertiesPtr;
67 struct TextCharacterProperties;
68 typedef std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr;
70 struct EffectProperties;
71 typedef std::shared_ptr< EffectProperties > EffectPropertiesPtr;
73 class TextBody;
74 typedef std::shared_ptr< TextBody > TextBodyPtr;
76 class TextListStyle;
77 typedef std::shared_ptr< TextListStyle > TextListStylePtr;
79 class Shape;
80 typedef std::shared_ptr< Shape > ShapePtr;
81 typedef std::weak_ptr< Shape > WeakShapePtr;
83 class Theme;
84 typedef std::shared_ptr< Theme > ThemePtr;
87 namespace table {
89 class TableProperties;
90 typedef std::shared_ptr< TableProperties > TablePropertiesPtr;
92 } // namespace table
95 /** converts the attributes from a CT_TLPoint into an awt Point with 1/1000% */
96 css::awt::Point GetPointPercent( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttribs );
99 /** converts the attributes from a CT_Size2D into an awt Size with 1/100th mm */
100 css::awt::Size GetSize2D( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
102 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
103 css::geometry::IntegerRectangle2D GetRelativeRect( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
105 void fillRelativeRectangle(model::RelativeRectangle& rRelativeRectangle,
106 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttributes);
108 /** converts EMUs into 1/100th mmm */
109 sal_Int32 GetCoordinate( sal_Int32 nValue );
111 /** converts an emu string into 1/100th mmm */
112 sal_Int32 GetCoordinate( std::u16string_view sValue );
114 /** converts 1/100mm to EMU */
115 sal_Int32 GetPointFromCoordinate( sal_Int32 nValue );
117 /** converts a ST_Percentage % string into 1/1000th of % */
118 sal_Int32 GetPercent( std::u16string_view sValue );
120 /** Converts a ST_PositiveFixedPercentage to a float. 1.0 == 100% */
121 double GetPositiveFixedPercentage( const OUString& sValue );
123 /** converts the ST_TextFontSize to point */
124 float GetTextSize( std::u16string_view rValue );
126 /** converts the ST_TextSpacingPoint to 1/100mm */
127 sal_Int32 GetTextSpacingPoint( std::u16string_view sValue );
128 sal_Int32 GetTextSpacingPoint( const sal_Int32 nValue );
130 /** */
131 css::style::TabAlign GetTabAlign( ::sal_Int32 aToken );
133 float GetFontHeight( sal_Int32 nHeight );
135 sal_Int16 GetFontUnderline( sal_Int32 nToken );
137 sal_Int16 GetFontStrikeout( sal_Int32 nToken );
139 sal_Int16 GetCaseMap( sal_Int32 nToken );
141 /** converts a paragraph align to a ParaAdjust */
142 css::style::ParagraphAdjust GetParaAdjust( sal_Int32 nAlign );
144 // Converts vertical adjust tokens to a TextVerticalAdjust item
145 css::drawing::TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken );
147 // Converts a TextVerticalAdjust item to string value appearing in ooxml
148 OOX_DLLPUBLIC const char* GetTextVerticalAdjust( css::drawing::TextVerticalAdjust eAdjust );
150 // Converts a Hatch object to an ooxml pattern.
151 const char* GetHatchPattern( const css::drawing::Hatch& rHatch );
153 /// Converts nRotate angle to TextVerticalType string appearing in ooxml
154 std::optional<OString> GetTextVerticalType(sal_Int32 nRotateAngle);
156 // CT_IndexRange
157 struct IndexRange {
158 sal_Int32 start;
159 sal_Int32 end;
162 /** retrieve the content of CT_IndexRange */
163 IndexRange GetIndexRange( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
166 * nRotation is a 100th of a degree and the return value is
167 * in a 60,000th of a degree
169 * Also rotation is in opposite directions so multiply with -1
171 inline OString calcRotationValue(sal_Int32 nRotation)
173 if (nRotation > 18000) // 180 degree
175 nRotation -= 36000;
177 nRotation *= -600;
178 return OString::number(nRotation);
181 /** Converts the passed 32-bit integer value from 1/100 mm to EMUs. */
182 inline sal_Int64 convertHmmToEmu( sal_Int32 nValue )
184 return o3tl::convert(nValue, o3tl::Length::mm100, o3tl::Length::emu);
187 /** Converts the passed 64-bit integer value from EMUs to 1/100 mm. */
188 inline sal_Int32 convertEmuToHmm( sal_Int64 nValue )
190 return o3tl::convertNarrowing<sal_Int32, o3tl::Length::emu, o3tl::Length::mm100>(nValue);
193 /** Converts the passed 64-bit integer value from EMUs to Points. */
194 inline float convertEmuToPoints( sal_Int64 nValue )
196 return o3tl::convert<double>(nValue, o3tl::Length::emu, o3tl::Length::pt);
199 /** Converts the passed double value from points to mm. */
200 inline double convertPointToMms(double fValue)
202 return o3tl::convert(fValue, o3tl::Length::pt, o3tl::Length::mm);
205 /** A structure for a point with 64-bit integer components. */
206 struct EmuPoint
208 sal_Int64 X;
209 sal_Int64 Y;
211 EmuPoint() : X( 0 ), Y( 0 ) {}
212 explicit EmuPoint( sal_Int64 nX, sal_Int64 nY ) : X( nX ), Y( nY ) {}
216 /** A structure for a size with 64-bit integer components. */
217 struct EmuSize
219 sal_Int64 Width;
220 sal_Int64 Height;
222 EmuSize() : Width( 0 ), Height( 0 ) {}
223 explicit EmuSize( sal_Int64 nWidth, sal_Int64 nHeight ) : Width( nWidth ), Height( nHeight ) {}
227 /** A structure for a rectangle with 64-bit integer components. */
228 struct EmuRectangle : public EmuPoint, public EmuSize
230 EmuRectangle() {}
231 explicit EmuRectangle( sal_Int64 nX, sal_Int64 nY, sal_Int64 nWidth, sal_Int64 nHeight ) : EmuPoint( nX, nY ), EmuSize( nWidth, nHeight ) {}
233 void setPos( const EmuPoint& rPos ) { static_cast< EmuPoint& >( *this ) = rPos; }
234 void setSize( const EmuSize& rSize ) { static_cast< EmuSize& >( *this ) = rSize; }
237 model::RectangleAlignment convertToRectangleAlignment(sal_Int32 nToken);
239 } // namespace oox::drawingml
241 #endif
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */