1/*
2 * Copyright 2006-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus <superstippi@gmx.de>
7 */
8#ifndef FLAT_ICON_EXPORTER_H
9#define FLAT_ICON_EXPORTER_H
10
11
12#include "Exporter.h"
13
14
15class BMessage;
16class BNode;
17class BPositionIO;
18
19_BEGIN_ICON_NAMESPACE
20	template <class Type> class Container;
21	class Gradient;
22	class LittleEndianBuffer;
23	class Shape;
24	class Style;
25	class VectorPath;
26_END_ICON_NAMESPACE
27
28
29#define HVIF_EXPORTER_ERRORS_BASE		(B_ERRORS_END + 1)
30#define E_TOO_MANY_PATHS				(HVIF_EXPORTER_ERRORS_BASE + 0)
31#define E_PATH_TOO_MANY_POINTS			(HVIF_EXPORTER_ERRORS_BASE + 1)
32#define E_TOO_MANY_SHAPES				(HVIF_EXPORTER_ERRORS_BASE + 2)
33#define E_SHAPE_TOO_MANY_PATHS			(HVIF_EXPORTER_ERRORS_BASE + 3)
34#define E_SHAPE_TOO_MANY_TRANSFORMERS	(HVIF_EXPORTER_ERRORS_BASE + 4)
35#define E_TOO_MANY_STYLES				(HVIF_EXPORTER_ERRORS_BASE + 5)
36
37
38#define PRINT_STATISTICS 0
39
40#if PRINT_STATISTICS
41# include <Point.h>
42# include <hash_set>
43
44#if __GNUC__ >= 4
45  using __gnu_cxx::hash_set;
46#endif
47
48class PointHash {
49 public:
50	int operator()(const BPoint& point) const
51	{
52		return (int)point.x * 17 + (int)point.y;
53	}
54};
55
56typedef hash_set<BPoint, PointHash> PointSet;
57#endif
58
59/*! Export to HVIF file or to an existing file's attribute. */
60class FlatIconExporter : public Exporter {
61 public:
62								FlatIconExporter();
63	virtual						~FlatIconExporter();
64
65	// Exporter interface
66	virtual	status_t			Export(const Icon* icon,
67									   BPositionIO* stream);
68	virtual const char*			ErrorCodeToString(status_t code);
69	virtual	const char*			MIMEType() { return NULL; }
70
71	// FlatIconExporter
72	/*! Export to file attribute */
73	status_t					Export(const Icon* icon, BNode* node,
74									   const char* attrName);
75
76 private:
77			status_t			_Export(LittleEndianBuffer& buffer,
78										const Icon* icon);
79
80			status_t			_WriteStyles(LittleEndianBuffer& buffer,
81											 const Container<Style>* styles);
82			status_t			_WritePaths(LittleEndianBuffer& buffer,
83											const Container<VectorPath>* paths);
84			status_t			_WriteShapes(LittleEndianBuffer& buffer,
85											 const Container<Style>* styles,
86											 const Container<VectorPath>* paths,
87											 const Container<Shape>* shapes);
88
89			bool				_WriteGradient(LittleEndianBuffer& buffer,
90											   const Gradient* gradient);
91
92			bool				_AnalysePath(VectorPath* path,
93											 uint8 pointCount,
94											 int32& straightCount,
95											 int32& lineCount,
96											 int32& curveCount);
97
98#if PRINT_STATISTICS
99			int32				fStyleSectionSize;
100			int32				fGradientSize;
101			int32				fGradientTransformSize;
102			int32				fPathSectionSize;
103			int32				fShapeSectionSize;
104
105			PointSet			fUsedPoints;
106			int32				fPointCount;
107#endif // PRINT_STATISTICS
108};
109
110#endif // FLAT_ICON_EXPORTER_H
111