bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / accessibility / AccessibleStringWrap.cxx
blobecddbd32a75faf393efd0ad51c3d0ddee6f09e21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <algorithm>
22 #include <tools/debug.hxx>
23 #include <vcl/outdev.hxx>
25 #include <editeng/svxfont.hxx>
26 #include <editeng/AccessibleStringWrap.hxx>
30 // AccessibleStringWrap implementation
34 AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, const OUString& rText ) :
35 mrDev( rDev ),
36 mrFont( rFont ),
37 maText( rText )
41 void AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, Rectangle& rRect )
43 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
44 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow");
46 mrFont.SetPhysFont( &mrDev );
48 // #108900# Handle virtual position one-past-the end of the string
49 if( nIndex >= maText.getLength() )
51 // create a caret bounding rect that has the height of the
52 // current font and is one pixel wide.
53 rRect.Left() = mrDev.GetTextWidth(maText);
54 rRect.Top() = 0;
55 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) );
57 else
59 long aXArray[2];
60 mrDev.GetCaretPositions( maText, aXArray, static_cast< sal_uInt16 >(nIndex), 1 );
61 rRect.Left() = 0;
62 rRect.Top() = 0;
63 rRect.SetSize( Size(mrDev.GetTextHeight(), labs(aXArray[0] - aXArray[1])) );
64 rRect.Move( ::std::min(aXArray[0], aXArray[1]), 0 );
67 if( mrFont.IsVertical() )
69 // #101701# Rotate to vertical
70 rRect = Rectangle( Point(-rRect.Top(), rRect.Left()),
71 Point(-rRect.Bottom(), rRect.Right()));
75 sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint )
77 // search for character bounding box containing given point
78 Rectangle aRect;
79 sal_Int32 i, nLen = maText.getLength();
80 for( i=0; i<nLen; ++i )
82 GetCharacterBounds(i, aRect);
83 if( aRect.IsInside(rPoint) )
84 return i;
87 return -1;
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */