/src/libreoffice/editeng/source/accessibility/AccessibleStringWrap.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 | | |
21 | | #include <tools/debug.hxx> |
22 | | #include <utility> |
23 | | #include <vcl/outdev.hxx> |
24 | | |
25 | | #include <editeng/svxfont.hxx> |
26 | | #include <AccessibleStringWrap.hxx> |
27 | | |
28 | | |
29 | | // AccessibleStringWrap implementation |
30 | | |
31 | | |
32 | | AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, OUString aText ) : |
33 | 0 | mrDev( rDev ), |
34 | 0 | mrFont( rFont ), |
35 | 0 | maText(std::move( aText )) |
36 | 0 | { |
37 | 0 | } |
38 | | |
39 | | void AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, tools::Rectangle& rRect ) |
40 | 0 | { |
41 | 0 | DBG_ASSERT(nIndex >= 0, |
42 | 0 | "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow"); |
43 | |
|
44 | 0 | mrFont.SetPhysFont(mrDev); |
45 | | |
46 | | // #108900# Handle virtual position one-past-the end of the string |
47 | 0 | if( nIndex >= maText.getLength() ) |
48 | 0 | { |
49 | | // create a caret bounding rect that has the height of the |
50 | | // current font and is one pixel wide. |
51 | 0 | rRect.SetLeft( mrDev.GetTextWidth(maText) ); |
52 | 0 | rRect.SetTop( 0 ); |
53 | 0 | rRect.SetSize( Size(mrDev.GetTextHeight(), 1) ); |
54 | 0 | } |
55 | 0 | else |
56 | 0 | { |
57 | 0 | KernArray aDXArray; |
58 | 0 | mrDev.GetTextArray(maText, &aDXArray, nIndex, 1); |
59 | 0 | rRect.SetLeft( 0 ); |
60 | 0 | rRect.SetTop( 0 ); |
61 | 0 | rRect.SetSize(Size(mrDev.GetTextHeight(), aDXArray[0])); |
62 | 0 | } |
63 | |
|
64 | 0 | if( mrFont.IsVertical() ) |
65 | 0 | { |
66 | | // #101701# Rotate to vertical |
67 | 0 | rRect = tools::Rectangle( Point(-rRect.Top(), rRect.Left()), |
68 | 0 | Point(-rRect.Bottom(), rRect.Right())); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint ) |
73 | 0 | { |
74 | | // search for character bounding box containing given point |
75 | 0 | tools::Rectangle aRect; |
76 | 0 | sal_Int32 i, nLen = maText.getLength(); |
77 | 0 | for( i=0; i<nLen; ++i ) |
78 | 0 | { |
79 | 0 | GetCharacterBounds(i, aRect); |
80 | 0 | if( aRect.Contains(rPoint) ) |
81 | 0 | return i; |
82 | 0 | } |
83 | | |
84 | 0 | return -1; |
85 | 0 | } |
86 | | |
87 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |