1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <tools/debug.hxx>
23 #include <vcl/outdev.hxx>
25 #include <editeng/svxfont.hxx>
26 #include <editeng/AccessibleStringWrap.hxx>
29 // AccessibleStringWrap implementation
32 AccessibleStringWrap::AccessibleStringWrap( OutputDevice
& rDev
, SvxFont
& rFont
, const OUString
& rText
) :
39 void AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex
, tools::Rectangle
& rRect
)
41 DBG_ASSERT(nIndex
>= 0,
42 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow");
44 mrFont
.SetPhysFont( &mrDev
);
46 // #108900# Handle virtual position one-past-the end of the string
47 if( nIndex
>= maText
.getLength() )
49 // create a caret bounding rect that has the height of the
50 // current font and is one pixel wide.
51 rRect
.SetLeft( mrDev
.GetTextWidth(maText
) );
53 rRect
.SetSize( Size(mrDev
.GetTextHeight(), 1) );
58 mrDev
.GetCaretPositions( maText
, aXArray
, nIndex
, 1 );
61 rRect
.SetSize( Size(mrDev
.GetTextHeight(), labs(aXArray
[0] - aXArray
[1])) );
62 rRect
.Move( std::min(aXArray
[0], aXArray
[1]), 0 );
65 if( mrFont
.IsVertical() )
67 // #101701# Rotate to vertical
68 rRect
= tools::Rectangle( Point(-rRect
.Top(), rRect
.Left()),
69 Point(-rRect
.Bottom(), rRect
.Right()));
73 sal_Int32
AccessibleStringWrap::GetIndexAtPoint( const Point
& rPoint
)
75 // search for character bounding box containing given point
76 tools::Rectangle aRect
;
77 sal_Int32 i
, nLen
= maText
.getLength();
78 for( i
=0; i
<nLen
; ++i
)
80 GetCharacterBounds(i
, aRect
);
81 if( aRect
.IsInside(rPoint
) )
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */