Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / drawinglayer / processor2d / hittestprocessor2d.hxx
blob6d092efe983ae95250aed3bb408a97401665f489
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 .
20 #ifndef INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
21 #define INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
23 #include <drawinglayer/drawinglayerdllapi.h>
24 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
25 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
27 namespace basegfx { class B2DPolygon; }
28 namespace basegfx { class B2DPolyPolygon; }
29 namespace drawinglayer::primitive2d { class ScenePrimitive2D; }
31 namespace drawinglayer::processor2d
33 /** HitTestProcessor2D class
35 This processor implements a HitTest with the fed primitives,
36 given tolerance and extras
38 class DRAWINGLAYER_DLLPUBLIC HitTestProcessor2D final : public BaseProcessor2D
40 private:
41 /// discrete HitTest position
42 basegfx::B2DPoint maDiscreteHitPosition;
44 /// discrete HitTolerance
45 basegfx::B2DVector maDiscreteHitTolerancePerAxis;
47 /// stack of HitPrimitives, taken care of during HitTest run
48 primitive2d::Primitive2DContainer maHitStack;
50 /// flag if HitStack shall be collected as part of the result, default is false
51 bool mbCollectHitStack : 1;
53 /// Boolean to flag if a hit was found. If yes, fast exit is taken
54 bool mbHit : 1;
56 /// flag to concentrate on text hits only
57 bool mbHitTextOnly : 1;
59 /// tooling methods
60 void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) override;
61 bool checkHairlineHitWithTolerance(
62 const basegfx::B2DPolygon& rPolygon,
63 const basegfx::B2DVector& rDiscreteHitTolerancePerAxis) const;
64 bool checkFillHitWithTolerance(
65 const basegfx::B2DPolyPolygon& rPolyPolygon,
66 const basegfx::B2DVector& rDiscreteHitTolerancePerAxis) const;
67 void check3DHit(const primitive2d::ScenePrimitive2D& rCandidate);
69 public:
70 HitTestProcessor2D(
71 const geometry::ViewInformation2D& rViewInformation,
72 const basegfx::B2DPoint& rLogicHitPosition,
73 const basegfx::B2DVector& rLogicHitTolerancePerAxis,
74 bool bHitTextOnly);
75 virtual ~HitTestProcessor2D() override;
77 /// switch on collecting primitives for a found hit on maHitStack, default is off
78 void collectHitStack(bool bCollect) { mbCollectHitStack = bCollect; }
80 /// get HitStack of primitives, first is the one that created the hit, last is the
81 /// top-most
82 const primitive2d::Primitive2DContainer& getHitStack() const { return maHitStack; }
84 /// data read access
85 const basegfx::B2DPoint& getDiscreteHitPosition() const { return maDiscreteHitPosition; }
86 const basegfx::B2DVector& getDiscreteHitTolerance() const { return maDiscreteHitTolerancePerAxis; }
87 bool getCollectHitStack() const { return mbCollectHitStack; }
88 bool getHit() const { return mbHit; }
89 bool getHitTextOnly() const { return mbHitTextOnly; }
92 } // end of namespace drawinglayer::processor2d
94 #endif // INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */