LibreOffice Module editeng (master) 1
AccessibleStringWrap.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <algorithm>
22#include <cstdlib>
23
24#include <tools/debug.hxx>
25#include <utility>
26#include <vcl/outdev.hxx>
27
28#include <editeng/svxfont.hxx>
30
31
32// AccessibleStringWrap implementation
33
34
36 mrDev( rDev ),
37 mrFont( rFont ),
38 maText(std::move( aText ))
39{
40}
41
43{
44 DBG_ASSERT(nIndex >= 0,
45 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow");
46
48
49 // #108900# Handle virtual position one-past-the end of the string
50 if( nIndex >= maText.getLength() )
51 {
52 // create a caret bounding rect that has the height of the
53 // current font and is one pixel wide.
55 rRect.SetTop( 0 );
56 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) );
57 }
58 else
59 {
60 KernArray aDXArray;
61 mrDev.GetTextArray(maText, &aDXArray, nIndex, 1);
62 rRect.SetLeft( 0 );
63 rRect.SetTop( 0 );
64 rRect.SetSize(Size(mrDev.GetTextHeight(), aDXArray[0]));
65 }
66
67 if( mrFont.IsVertical() )
68 {
69 // #101701# Rotate to vertical
70 rRect = tools::Rectangle( Point(-rRect.Top(), rRect.Left()),
71 Point(-rRect.Bottom(), rRect.Right()));
72 }
73}
74
76{
77 // search for character bounding box containing given point
78 tools::Rectangle aRect;
79 sal_Int32 i, nLen = maText.getLength();
80 for( i=0; i<nLen; ++i )
81 {
82 GetCharacterBounds(i, aRect);
83 if( aRect.Contains(rPoint) )
84 return i;
85 }
86
87 return -1;
88}
89
90/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Text maText
sal_Int32 GetIndexAtPoint(const Point &rPoint)
void GetCharacterBounds(sal_Int32 nIndex, tools::Rectangle &rRect)
AccessibleStringWrap(OutputDevice &rDev, SvxFont &rFont, OUString aText)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
tools::Long GetTextArray(const OUString &rStr, KernArray *pDXAry, sal_Int32 nIndex=0, sal_Int32 nLen=-1, bool bCaret=false, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
tools::Long GetTextHeight() const
void SetPhysFont(OutputDevice &rOut) const
Definition: svxfont.cxx:382
bool Contains(const Point &rPOINT) const
constexpr void SetLeft(tools::Long v)
constexpr void SetTop(tools::Long v)
constexpr tools::Long Top() const
void SetSize(const Size &)
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
bool IsVertical() const
#define DBG_ASSERT(sCon, aError)
sal_Int32 nIndex
int i