summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/HyperlinkManager.hpp
blob: 99151db0e5a0da381b36b763a6c5d51f02038170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*************************************************************************
** HyperlinkManager.hpp                                                 **
**                                                                      **
** This file is part of dvisvgm -- a fast DVI to SVG converter          **
** Copyright (C) 2005-2022 Martin Gieseking <martin.gieseking@uos.de>   **
**                                                                      **
** This program is free software; you can redistribute it and/or        **
** modify it under the terms of the GNU General Public License as       **
** published by the Free Software Foundation; either version 3 of       **
** the License, or (at your option) any later version.                  **
**                                                                      **
** This program is distributed in the hope that it will be useful, but  **
** WITHOUT ANY WARRANTY; without even the implied warranty of           **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
** GNU General Public License for more details.                         **
**                                                                      **
** You should have received a copy of the GNU General Public License    **
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
*************************************************************************/

#ifndef HYPERLINKMANAGER_HPP
#define HYPERLINKMANAGER_HPP

#include <string>
#include <unordered_map>
#include "Color.hpp"
#include "SpecialActions.hpp"

class SpecialActions;

class HyperlinkManager {
	struct NamedAnchor {
		NamedAnchor () : pageno(0), id(0), pos(0), referenced(false) {}
		NamedAnchor (unsigned pn, int i, double p, bool r=false) : pageno(pn), id(i), pos(p), referenced(r) {}
		unsigned pageno;  ///< page number where the anchor is located
		int id;           ///< unique numerical ID (< 0 if anchor is undefined yet)
		double pos;       ///< vertical position of named anchor (in PS point units)
		bool referenced;  ///< true if a reference to this anchor exists
	};

	enum class AnchorType {NONE, HREF, NAME};
	enum class ColorSource {DEFAULT, LINKMARKER, STATIC};
	using NamedAnchors = std::unordered_map<std::string, NamedAnchor>;

	public:
		HyperlinkManager (const HyperlinkManager&) =delete;
		HyperlinkManager (HyperlinkManager&&) =delete;
		void addHrefAnchor (const std::string &uri);
		void addNameAchor (const std::string &name, int pageno);
		void setActiveNameAnchor (const std::string &name, SpecialActions &actions);
		void closeAnchor (SpecialActions &actions);
		void checkNewLine (SpecialActions &actions);
		void createLink (std::string uri, SpecialActions &actions);
		void createViews (unsigned pageno, SpecialActions &actions);
		void setBaseUrl (const std::string &base) {_base = base;}
		void setLineWidth (double w) {_linewidth = w;}
		static HyperlinkManager& instance ();
		static bool setLinkMarker (const std::string &marker);
		static void setDefaultLinkColor (Color color);

	protected:
		HyperlinkManager () =default;
		void markLinkedBox (SpecialActions &actions);

		enum class MarkerType {NONE, LINE, BOX, BGCOLOR};
		static MarkerType MARKER_TYPE;  ///< selects how to mark linked areas
		static Color LINK_BGCOLOR;      ///< background color if linkmark type == LT_BGCOLOR
		static Color LINK_LINECOLOR;    ///< line color if linkmark type is LM_LINE or LM_BOX
		static ColorSource COLORSOURCE; ///< if true, LINK_LINECOLOR is applied

	private:
		AnchorType _anchorType=AnchorType::NONE;  ///< type of active anchor
		int _depthThreshold=0;      ///< break anchor box if the DVI stack depth underruns this threshold
		double _linewidth=-1;       ///< line width of link marker (-1 => compute individual value per link)
		std::string _base;          ///< base URL that is prepended to all relative targets
		NamedAnchors _namedAnchors; ///< information about all named anchors processed
};

#endif