1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_editeng.hxx" 26 27 #include <algorithm> 28 #include <tools/debug.hxx> 29 #include <vcl/outdev.hxx> 30 31 #include <editeng/svxfont.hxx> 32 #include <editeng/AccessibleStringWrap.hxx> 33 34 //------------------------------------------------------------------------ 35 // 36 // AccessibleStringWrap implementation 37 // 38 //------------------------------------------------------------------------ 39 40 AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, const String& rText ) : 41 mrDev( rDev ), 42 mrFont( rFont ), 43 maText( rText ) 44 { 45 } 46 47 sal_Bool AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, Rectangle& rRect ) 48 { 49 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX, 50 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow"); 51 52 mrFont.SetPhysFont( &mrDev ); 53 54 // #108900# Handle virtual position one-past-the end of the string 55 if( nIndex >= maText.Len() ) 56 { 57 // create a caret bounding rect that has the height of the 58 // current font and is one pixel wide. 59 rRect.Left() = mrDev.GetTextWidth(maText); 60 rRect.Top() = 0; 61 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) ); 62 } 63 else 64 { 65 sal_Int32 aXArray[2]; 66 mrDev.GetCaretPositions( maText, aXArray, static_cast< sal_uInt16 >(nIndex), 1 ); 67 rRect.Left() = 0; 68 rRect.Top() = 0; 69 rRect.SetSize( Size(mrDev.GetTextHeight(), labs(aXArray[0] - aXArray[1])) ); 70 rRect.Move( ::std::min(aXArray[0], aXArray[1]), 0 ); 71 } 72 73 if( mrFont.IsVertical() ) 74 { 75 // #101701# Rotate to vertical 76 rRect = Rectangle( Point(-rRect.Top(), rRect.Left()), 77 Point(-rRect.Bottom(), rRect.Right())); 78 } 79 80 return sal_True; 81 } 82 83 sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint ) 84 { 85 // search for character bounding box containing given point 86 Rectangle aRect; 87 sal_Int32 i, nLen = maText.Len(); 88 for( i=0; i<nLen; ++i ) 89 { 90 GetCharacterBounds(i, aRect); 91 if( aRect.IsInside(rPoint) ) 92 return i; 93 } 94 95 return -1; 96 } 97