1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 31 #include <algorithm> 32 #include <tools/debug.hxx> 33 #include <vcl/outdev.hxx> 34 35 #include <editeng/svxfont.hxx> 36 #include <editeng/AccessibleStringWrap.hxx> 37 38 //------------------------------------------------------------------------ 39 // 40 // AccessibleStringWrap implementation 41 // 42 //------------------------------------------------------------------------ 43 44 AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, const String& rText ) : 45 mrDev( rDev ), 46 mrFont( rFont ), 47 maText( rText ) 48 { 49 } 50 51 sal_Bool AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, Rectangle& rRect ) 52 { 53 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX, 54 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow"); 55 56 mrFont.SetPhysFont( &mrDev ); 57 58 // #108900# Handle virtual position one-past-the end of the string 59 if( nIndex >= maText.Len() ) 60 { 61 // create a caret bounding rect that has the height of the 62 // current font and is one pixel wide. 63 rRect.Left() = mrDev.GetTextWidth(maText); 64 rRect.Top() = 0; 65 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) ); 66 } 67 else 68 { 69 sal_Int32 aXArray[2]; 70 mrDev.GetCaretPositions( maText, aXArray, static_cast< sal_uInt16 >(nIndex), 1 ); 71 rRect.Left() = 0; 72 rRect.Top() = 0; 73 rRect.SetSize( Size(mrDev.GetTextHeight(), labs(aXArray[0] - aXArray[1])) ); 74 rRect.Move( ::std::min(aXArray[0], aXArray[1]), 0 ); 75 } 76 77 if( mrFont.IsVertical() ) 78 { 79 // #101701# Rotate to vertical 80 rRect = Rectangle( Point(-rRect.Top(), rRect.Left()), 81 Point(-rRect.Bottom(), rRect.Right())); 82 } 83 84 return sal_True; 85 } 86 87 sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint ) 88 { 89 // search for character bounding box containing given point 90 Rectangle aRect; 91 sal_Int32 i, nLen = maText.Len(); 92 for( i=0; i<nLen; ++i ) 93 { 94 GetCharacterBounds(i, aRect); 95 if( aRect.IsInside(rPoint) ) 96 return i; 97 } 98 99 return -1; 100 } 101