LibreOffice Module sw (master)  1
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
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 .
18  */
23 #include <SwPortionHandler.hxx>
24 #include <sal/types.h>
25 #include <rtl/ustrbuf.hxx>
26 #include <memory>
27 #include <vector>
29 class SwTextFrame;
30 struct SwSpecialPos;
31 class SwViewOption;
32 namespace com::sun::star {
33  namespace i18n { struct Boundary; }
34 }
40 {
41  // the frame this portion is referring to
44  // variables used while collecting the data
45  OUStringBuffer m_aBuffer;
55  // positions array
56  // instances of Position_t must always include the minimum and
57  // maximum positions as first/last elements (to simplify the
58  // algorithms)
59  typedef std::vector<sal_Int32> AccessiblePositions;
60  typedef std::vector<TextFrameIndex> FramePositions;
62  AccessiblePositions m_aLineBreaks;
63  FramePositions m_ViewPositions;
64  AccessiblePositions m_aAccessiblePositions;
65  AccessiblePositions m_aFieldPosition;
67  std::vector<sal_uInt8> m_aPortionAttrs;
69  std::unique_ptr<AccessiblePositions> m_pSentences;
75  static void FillBoundary(css::i18n::Boundary& rBound,
76  const AccessiblePositions& rPositions,
77  size_t nPos );
80  bool IsPortionAttrSet( size_t nPortionNo, sal_uInt8 nAttr ) const;
81  bool IsSpecialPortion( size_t nPortionNo ) const;
82  bool IsGrayPortionType( PortionType nType ) const;
84  // helper method for GetEditableRange(...):
85  void AdjustAndCheck( sal_Int32 nPos, size_t& nPortionNo,
86  TextFrameIndex& rCorePos, bool& bEdit) const;
88 public:
89  SwAccessiblePortionData( const SwTextFrame* pTextFrame,
90  const SwViewOption* pViewOpt );
91  virtual ~SwAccessiblePortionData() override;
93  // SwPortionHandler methods
94  virtual void Text(TextFrameIndex nLength, PortionType nType, sal_Int32 nHeight = 0, sal_Int32 nWidth = 0) override;
95  virtual void Special(TextFrameIndex nLength, const OUString& rText, PortionType nType, sal_Int32 nHeight = 0, sal_Int32 nWidth = 0, const SwFont* pFont = nullptr) override;
96  virtual void LineBreak(sal_Int32 nWidth) override;
97  virtual void Skip(TextFrameIndex nLength) override;
98  virtual void Finish() override;
100  bool FillBoundaryIFDateField( css::i18n::Boundary& rBound, const sal_Int32 nPos );
101  bool IsIndexInFootnode(sal_Int32 nIndex);
102  bool IsInGrayPortion( sal_Int32 nPos );
103  sal_Int32 GetFieldIndex(sal_Int32 nPos) const;
105  bool IsZeroCorePositionData();
107  // access to the portion data
110  const OUString& GetAccessibleString() const;
113  void GetLineBoundary( css::i18n::Boundary& rBound,
114  sal_Int32 nPos ) const;
116  // get start and end position of the last line
117  void GetLastLineBoundary( css::i18n::Boundary& rBound ) const;
124  bool IsValidCorePosition(TextFrameIndex nPos) const;
129  sal_Int32 GetAccessiblePosition(TextFrameIndex nPos) const;
131  // #i89175#
132  sal_Int32 GetLineCount() const;
133  sal_Int32 GetLineNo( const sal_Int32 nPos ) const;
134  void GetBoundaryOfLine( const sal_Int32 nLineNo,
135  css::i18n::Boundary& rLineBound );
139  TextFrameIndex GetCoreViewPosition(sal_Int32 nPos) const;
145  TextFrameIndex FillSpecialPos(sal_Int32 nPos,
146  SwSpecialPos& rPos,
147  SwSpecialPos*& rpPos ) const;
149  // get boundaries of words/sentences. The data structures are
150  // created on-demand.
151  void GetSentenceBoundary( css::i18n::Boundary& rBound,
152  sal_Int32 nPos );
154  // get (a) boundary for attribute change
155  void GetAttributeBoundary( css::i18n::Boundary& rBound,
156  sal_Int32 nPos ) const;
162  bool GetEditableRange( sal_Int32 nStart, sal_Int32 nEnd,
163  TextFrameIndex& rCoreStart, TextFrameIndex& rCoreEnd) const;
165 private:
166  std::vector< std::pair<sal_Int32,sal_Int32> > m_vecPairPos;
167 };
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetAccessibleString() const
get the text string, as presented by the layout
const SwViewOption * m_pViewOptions
Definition: accportions.hxx:47
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
SwAccessiblePortionData(const SwTextFrame *pTextFrame, const SwViewOption *pViewOpt)
Definition: accportions.cxx:64
AccessiblePositions m_aLineBreaks
Definition: accportions.hxx:62
virtual ~SwAccessiblePortionData() override
Definition: accportions.cxx:91
virtual void LineBreak(sal_Int32 nWidth) override
line break.
TextFrameIndex FillSpecialPos(sal_Int32 nPos, SwSpecialPos &rPos, SwSpecialPos *&rpPos) const
fill a SwSpecialPos structure, suitable for calling SwTextFrame->GetCharRect Returns the core positio...
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
TextFrameIndex GetFirstValidCorePosition() const
bool IsGrayPortionType(PortionType nType) const
OUString m_sAccessibleString
the accessible string note that the content is different both from the string in the text node(s) as ...
Definition: accportions.hxx:53
FramePositions m_ViewPositions
position of line breaks
Definition: accportions.hxx:63
void AdjustAndCheck(sal_Int32 nPos, size_t &nPortionNo, TextFrameIndex &rCorePos, bool &bEdit) const
std::vector< sal_uInt8 > m_aPortionAttrs
Definition: accportions.hxx:67
OUStringBuffer m_aBuffer
Definition: accportions.hxx:45
size_t m_nBeforePortions
positions of sentence breaks
Definition: accportions.hxx:71
std::vector< std::pair< sal_Int32, sal_Int32 > > m_vecPairPos
sal_Int32 GetLineCount() const
virtual void Text(TextFrameIndex nLength, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0) override
(empty) destructor
Definition: accportions.cxx:95
virtual void Skip(TextFrameIndex nLength) override
skip characters.
void GetAttributeBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
void GetLineBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
get the start & end positions of the sentence
std::unique_ptr< AccessiblePositions > m_pSentences
additional portion attributes
Definition: accportions.hxx:69
bool IsInGrayPortion(sal_Int32 nPos)
TextFrameIndex GetLastValidCorePosition() const
bool GetEditableRange(sal_Int32 nStart, sal_Int32 nEnd, TextFrameIndex &rCoreStart, TextFrameIndex &rCoreEnd) const
Convert start and end positions into core positions.
void GetBoundaryOfLine(const sal_Int32 nLineNo, css::i18n::Boundary &rLineBound)
static void FillBoundary(css::i18n::Boundary &rBound, const AccessiblePositions &rPositions, size_t nPos)
fill the boundary with the values from rPositions[nPos]
bool FillBoundaryIFDateField(css::i18n::Boundary &rBound, const sal_Int32 nPos)
exports i18n
void GetSentenceBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos)
TextFrameIndex GetCoreViewPosition(sal_Int32 nPos) const
get the position in the core view string for a given (accessibility) position
Definition: txttypes.hxx:23
collect text portion data from the layout through SwPortionHandler interface
Definition: accportions.hxx:39
TextFrameIndex m_nViewPosition
Definition: accportions.hxx:46
std::vector< TextFrameIndex > FramePositions
Definition: accportions.hxx:60
virtual void Finish() override
end of paragraph.
bool IsValidCorePosition(TextFrameIndex nPos) const
Determine whether this core position is valid for these portions.
std::vector< sal_Int32 > AccessiblePositions
Definition: accportions.hxx:59
unsigned char sal_uInt8
sal_Int32 GetLineNo(const sal_Int32 nPos) const
bool IsPortionAttrSet(size_t nPortionNo, sal_uInt8 nAttr) const
Access to portion attributes.
bool m_bFinished
of portions before first core character
Definition: accportions.hxx:72
AccessiblePositions m_aAccessiblePositions
position of portion breaks in the core view
Definition: accportions.hxx:64
void GetLastLineBoundary(css::i18n::Boundary &rBound) const
AccessiblePositions m_aFieldPosition
portion breaks in m_sAccessibleString
Definition: accportions.hxx:65
SwTextFrame const * m_pTextFrame
Definition: accportions.hxx:42
sal_Int32 GetAccessiblePosition(TextFrameIndex nPos) const
get the position in the accessibility string for a given view position
bool IsSpecialPortion(size_t nPortionNo) const
sal_Int32 GetFieldIndex(sal_Int32 nPos) const
bool IsIndexInFootnode(sal_Int32 nIndex)
virtual void Special(TextFrameIndex nLength, const OUString &rText, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0, const SwFont *pFont=nullptr) override
special portion.