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