/src/libreoffice/vcl/source/accessibility/characterattributeshelper.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <tools/gen.hxx> |
21 | | #include <vcl/accessibility/characterattributeshelper.hxx> |
22 | | #include <vcl/unohelp.hxx> |
23 | | #include <comphelper/sequence.hxx> |
24 | | |
25 | | using namespace ::com::sun::star::uno; |
26 | | using namespace ::com::sun::star::beans; |
27 | | |
28 | | |
29 | | CharacterAttributesHelper::CharacterAttributesHelper( const vcl::Font& rFont, sal_Int32 nBackColor, sal_Int32 nColor ) |
30 | 0 | { |
31 | 0 | m_aAttributeMap.emplace( u"CharBackColor"_ustr, Any( nBackColor ) ); |
32 | 0 | m_aAttributeMap.emplace( u"CharColor"_ustr, Any( nColor ) ); |
33 | 0 | m_aAttributeMap.emplace( u"CharFontCharSet"_ustr, Any( static_cast<sal_Int16>(rFont.GetCharSet()) ) ); |
34 | 0 | m_aAttributeMap.emplace( u"CharFontFamily"_ustr, Any( static_cast<sal_Int16>(rFont.GetFamilyType()) ) ); |
35 | 0 | m_aAttributeMap.emplace( u"CharFontName"_ustr, Any( rFont.GetFamilyName() ) ); |
36 | 0 | m_aAttributeMap.emplace( u"CharFontPitch"_ustr, Any( static_cast<sal_Int16>(rFont.GetPitch()) ) ); |
37 | 0 | m_aAttributeMap.emplace( u"CharFontStyleName"_ustr, Any( rFont.GetStyleName() ) ); |
38 | 0 | m_aAttributeMap.emplace( u"CharHeight"_ustr, Any( static_cast<sal_Int16>(rFont.GetFontSize().Height()) ) ); |
39 | 0 | m_aAttributeMap.emplace( u"CharScaleWidth"_ustr, Any( static_cast<sal_Int16>(rFont.GetFontSize().Width()) ) ); |
40 | 0 | m_aAttributeMap.emplace( u"CharStrikeout"_ustr, Any( static_cast<sal_Int16>(rFont.GetStrikeout()) ) ); |
41 | 0 | m_aAttributeMap.emplace( u"CharUnderline"_ustr, Any( static_cast<sal_Int16>(rFont.GetUnderline()) ) ); |
42 | 0 | m_aAttributeMap.emplace( u"CharWeight"_ustr, Any( static_cast<float>(rFont.GetWeight()) ) ); |
43 | 0 | m_aAttributeMap.emplace( u"CharPosture"_ustr, Any( vcl::unohelper::ConvertFontSlant(rFont.GetItalic()) ) ); |
44 | 0 | } |
45 | | |
46 | | |
47 | | std::vector< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes() |
48 | 0 | { |
49 | 0 | std::vector< PropertyValue > aValues; |
50 | 0 | aValues.reserve( m_aAttributeMap.size() ); |
51 | |
|
52 | 0 | for ( const auto& aIt : m_aAttributeMap) |
53 | 0 | { |
54 | 0 | aValues.emplace_back(aIt.first, sal_Int32(-1), aIt.second, PropertyState_DIRECT_VALUE); |
55 | 0 | } |
56 | |
|
57 | 0 | return aValues; |
58 | 0 | } |
59 | | |
60 | | |
61 | | Sequence< PropertyValue > CharacterAttributesHelper::GetCharacterAttributes( const css::uno::Sequence< OUString >& aRequestedAttributes ) |
62 | 0 | { |
63 | 0 | if ( !aRequestedAttributes.hasElements() ) |
64 | 0 | return comphelper::containerToSequence(GetCharacterAttributes()); |
65 | | |
66 | 0 | std::vector< PropertyValue > aValues; |
67 | |
|
68 | 0 | for ( const auto& aRequestedAttribute: aRequestedAttributes) |
69 | 0 | { |
70 | 0 | AttributeMap::iterator aFound = m_aAttributeMap.find( aRequestedAttribute ); |
71 | 0 | if ( aFound != m_aAttributeMap.end() ) |
72 | 0 | aValues.emplace_back(aFound->first, sal_Int32(-1), aFound->second, PropertyState_DIRECT_VALUE); |
73 | 0 | } |
74 | |
|
75 | 0 | return comphelper::containerToSequence(aValues); |
76 | 0 | } |
77 | | |
78 | | |
79 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |