1 /*************************************************************************
2 ** HtmlSpecialHandler.h                                                 **
3 **                                                                      **
4 ** This file is part of dvisvgm -- the DVI to SVG converter             **
5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de>   **
6 **                                                                      **
7 ** This program is free software; you can redistribute it and/or        **
8 ** modify it under the terms of the GNU General Public License as       **
9 ** published by the Free Software Foundation; either version 3 of       **
10 ** the License, or (at your option) any later version.                  **
11 **                                                                      **
12 ** This program is distributed in the hope that it will be useful, but  **
13 ** WITHOUT ANY WARRANTY; without even the implied warranty of           **
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
15 ** GNU General Public License for more details.                         **
16 **                                                                      **
17 ** You should have received a copy of the GNU General Public License    **
18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. **
19 *************************************************************************/
20 
21 #ifndef DVISVGM_HTMLSPECIALHANDLER_H
22 #define DVISVGM_HTMLSPECIALHANDLER_H
23 
24 #include <map>
25 #include <string>
26 #include "Color.h"
27 #include "SpecialHandler.h"
28 
29 struct SpecialActions;
30 
31 class HtmlSpecialHandler : public SpecialHandler, public DVIEndPageListener, public DVIPositionListener
32 {
33 	struct NamedAnchor {
NamedAnchorNamedAnchor34 		NamedAnchor () : pageno(0), id(0), pos(0), referenced(false) {}
pagenoNamedAnchor35 		NamedAnchor (unsigned pn, int i, double p, bool r=false) : pageno(pn), id(i), pos(p), referenced(r) {}
36 		unsigned pageno;  ///< page number where the anchor is located
37 		int id;           ///< unique numerical ID (< 0 if anchor is undefined yet)
38 		double pos;       ///< vertical position of named anchor (in PS point units)
39 		bool referenced;  ///< true if a reference to this anchor exists
40 	};
41 
42 	enum AnchorType {AT_NONE, AT_HREF, AT_NAME};
43 	typedef std::map<std::string, NamedAnchor> NamedAnchors;
44 
45 	public:
HtmlSpecialHandler()46 		HtmlSpecialHandler () : _actions(0), _anchorType(AT_NONE), _depthThreshold(0) {}
47 		void preprocess(const char *prefix, std::istream &is, SpecialActions *actions);
48 		bool process (const char *prefix, std::istream &is, SpecialActions *actions);
name()49 		const char* name () const  {return "html";}
info()50 		const char* info () const  {return "hyperref specials";}
51 		const char** prefixes () const;
52 
53 		static bool setLinkMarker (const std::string &marker);
54 
55 	protected:
56 		void preprocessHrefAnchor (const std::string &uri);
57 		void preprocessNameAnchor (const std::string &name);
58 		void processHrefAnchor (std::string uri);
59 		void processNameAnchor (const std::string &name);
60 		void dviEndPage (unsigned pageno);
61 		void dviMovedTo (double x, double y);
62 		void closeAnchor ();
63 		void markLinkedBox ();
64 
65 		enum MarkerType {MT_NONE, MT_LINE, MT_BOX, MT_BGCOLOR};
66 		static MarkerType MARKER_TYPE;  ///< selects how to mark linked areas
67 		static Color LINK_BGCOLOR;      ///< background color if linkmark type == LT_BGCOLOR
68 		static Color LINK_LINECOLOR;    ///< line color if linkmark type is LM_LINE or LM_BOX
69 		static bool USE_LINECOLOR;      ///< if true, LINK_LINECOLOR is applied
70 
71 	private:
72 		SpecialActions *_actions;
73 		AnchorType _anchorType;     ///< type of active anchor
74 		int _depthThreshold;        ///< break anchor box if the DVI stack depth underruns this threshold
75 		std::string _base;          ///< base URL that is prepended to all relative targets
76 		NamedAnchors _namedAnchors; ///< information about all named anchors processed
77 };
78 
79 #endif
80