/src/libreoffice/vcl/inc/textlayout.hxx
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 | | #pragma once |
21 | | |
22 | | #include <tools/long.hxx> |
23 | | #include <vcl/outdev.hxx> |
24 | | |
25 | | #include <memory> |
26 | | #include <vector> |
27 | | |
28 | | #include <com/sun/star/i18n/WordType.hpp> |
29 | | #include <com/sun/star/i18n/XBreakIterator.hpp> |
30 | | #include <com/sun/star/linguistic2/LinguServiceManager.hpp> |
31 | | |
32 | | class Control; |
33 | | class ImplMultiTextLineInfo; |
34 | | |
35 | | namespace vcl |
36 | | { |
37 | | class VCL_DLLPUBLIC TextLayoutCommon |
38 | | { |
39 | | public: |
40 | | virtual tools::Long GetTextWidth( const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0; |
41 | | virtual void DrawText( const Point& _rStartPoint, const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength, |
42 | | std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText ) = 0; |
43 | | virtual tools::Long GetTextArray( const OUString& _rText, KernArray* _pDXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength, bool bCaret = false ) const = 0; |
44 | | virtual sal_Int32 GetTextBreak( const OUString& _rText, tools::Long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0; |
45 | | virtual bool DecomposeTextRectAction() const = 0; |
46 | | |
47 | | SAL_DLLPRIVATE OUString GetEllipsisString(OUString const& rOrigStr, tools::Long nMaxWidth, DrawTextFlags nStyle); |
48 | | |
49 | | std::tuple<sal_Int32, sal_Int32> BreakLine(const tools::Long nWidth, OUString const& rStr, |
50 | | css::uno::Reference< css::linguistic2::XHyphenator > const& xHyph, |
51 | | css::uno::Reference<css::i18n::XBreakIterator>& xBI, |
52 | | const bool bHyphenate, const tools::Long nOrigLineWidth, |
53 | | const sal_Int32 nPos, const sal_Int32 nLen); |
54 | | |
55 | | SAL_DLLPRIVATE std::tuple<sal_Int32, sal_Int32> BreakLineSimple(const tools::Long nWidth, OUString const& rStr, |
56 | | const sal_Int32 nPos, sal_Int32 nBreakPos, const tools::Long nOrigLineWidth); |
57 | | |
58 | | SAL_DLLPRIVATE tools::Long GetTextLines(tools::Rectangle const& rRect, const tools::Long nTextHeight, |
59 | | ImplMultiTextLineInfo& rLineInfo, |
60 | | tools::Long nWidth, OUString const& rStr, |
61 | | DrawTextFlags nStyle); |
62 | | |
63 | | protected: |
64 | | SAL_DLLPRIVATE ~TextLayoutCommon(); |
65 | | |
66 | | private: |
67 | | SAL_DLLPRIVATE OUString GetCenterEllipsisString(std::u16string_view rOrigStr, sal_Int32 nIndex, tools::Long nMaxWidth); |
68 | | SAL_DLLPRIVATE OUString GetEndEllipsisString(OUString const& rOrigStr, sal_Int32 nIndex, tools::Long nMaxWidth, bool bClipText); |
69 | | SAL_DLLPRIVATE OUString GetNewsEllipsisString(OUString const& rOrigStr, tools::Long nMaxWidth, DrawTextFlags nStyle); |
70 | | }; |
71 | | |
72 | | /** is an implementation of TextLayoutCommon which simply delegates its calls to the respective |
73 | | methods of an OutputDevice instance, without any inbetween magic. |
74 | | */ |
75 | | class VCL_DLLPUBLIC DefaultTextLayout final : public TextLayoutCommon |
76 | | { |
77 | | public: |
78 | | DefaultTextLayout( OutputDevice& _rTargetDevice ) |
79 | 2.63k | : m_rTargetDevice( _rTargetDevice ) |
80 | 2.63k | { |
81 | 2.63k | } |
82 | | ~DefaultTextLayout(); |
83 | | |
84 | | // TextLayoutCommon overridables |
85 | | SAL_DLLPRIVATE virtual tools::Long GetTextWidth( const OUString& _rText, |
86 | | sal_Int32 _nStartIndex, |
87 | | sal_Int32 _nLength ) const override; |
88 | | |
89 | | virtual void DrawText( const Point& _rStartPoint, |
90 | | const OUString& _rText, |
91 | | sal_Int32 _nStartIndex, |
92 | | sal_Int32 _nLength, |
93 | | std::vector< tools::Rectangle >* _pVector, |
94 | | OUString* _pDisplayText ) override; |
95 | | |
96 | | SAL_DLLPRIVATE virtual tools::Long GetTextArray( const OUString& _rText, |
97 | | KernArray* _pDXArray, |
98 | | sal_Int32 _nStartIndex, |
99 | | sal_Int32 _nLength, |
100 | | bool bCaret = false ) const override; |
101 | | |
102 | | SAL_DLLPRIVATE virtual sal_Int32 GetTextBreak( const OUString& _rText, |
103 | | tools::Long _nMaxTextWidth, |
104 | | sal_Int32 _nStartIndex, |
105 | | sal_Int32 _nLength ) const override; |
106 | | |
107 | | SAL_DLLPRIVATE virtual bool DecomposeTextRectAction() const override; |
108 | | |
109 | | private: |
110 | | OutputDevice& m_rTargetDevice; |
111 | | }; |
112 | | |
113 | | class ReferenceDeviceTextLayout; |
114 | | /** a class which allows rendering text of a Control onto a device, by taking into account the metrics of |
115 | | a reference device. |
116 | | */ |
117 | | class ControlTextRenderer final |
118 | | { |
119 | | public: |
120 | | ControlTextRenderer( const Control& _rControl, OutputDevice& _rTargetDevice, OutputDevice& _rReferenceDevice ); |
121 | | ~ControlTextRenderer(); |
122 | | |
123 | | tools::Rectangle DrawText( const tools::Rectangle& _rRect, |
124 | | const OUString& _rText, DrawTextFlags _nStyle, |
125 | | std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText, const Size* i_pDeviceSize ); |
126 | | |
127 | | tools::Rectangle GetTextRect( const tools::Rectangle& _rRect, |
128 | | const OUString& _rText, DrawTextFlags _nStyle, Size* o_pDeviceSize ); |
129 | | |
130 | | private: |
131 | | ControlTextRenderer( const ControlTextRenderer& ) = delete; |
132 | | ControlTextRenderer& operator=( const ControlTextRenderer& ) = delete; |
133 | | |
134 | | private: |
135 | | ::std::unique_ptr< ReferenceDeviceTextLayout > m_pImpl; |
136 | | }; |
137 | | |
138 | | } // namespace vcl |
139 | | |
140 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |