/src/libstaroffice/src/lib/StarGraphicStruct.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libstaroffice |
4 | | * Version: MPL 2.0 / LGPLv2+ |
5 | | * |
6 | | * The contents of this file are subject to the Mozilla Public License Version |
7 | | * 2.0 (the "License"); you may not use this file except in compliance with |
8 | | * the License or as specified alternatively below. You may obtain a copy of |
9 | | * the License at http://www.mozilla.org/MPL/ |
10 | | * |
11 | | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | | * for the specific language governing rights and limitations under the |
14 | | * License. |
15 | | * |
16 | | * Major Contributor(s): |
17 | | * Copyright (C) 2002 William Lachance (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
22 | | * |
23 | | * |
24 | | * All Rights Reserved. |
25 | | * |
26 | | * For minor contributions see the git repository. |
27 | | * |
28 | | * Alternatively, the contents of this file may be used under the terms of |
29 | | * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
30 | | * in which case the provisions of the LGPLv2+ are applicable |
31 | | * instead of those above. |
32 | | */ |
33 | | |
34 | | #ifndef STAR_GRAPHIC_STRUCT |
35 | | # define STAR_GRAPHIC_STRUCT |
36 | | |
37 | | #include <ostream> |
38 | | #include <string> |
39 | | #include <vector> |
40 | | |
41 | | #include "libstaroffice_internal.hxx" |
42 | | |
43 | | class StarBitmap; |
44 | | class StarObject; |
45 | | class StarZone; |
46 | | |
47 | | //! a name use to define basic StarOffice graphic structure |
48 | | namespace StarGraphicStruct |
49 | | { |
50 | | //! Class to store a brush |
51 | | class StarBrush |
52 | | { |
53 | | public: |
54 | | //! constructor |
55 | | StarBrush() |
56 | 623k | : m_transparency(0) |
57 | 623k | , m_color(STOFFColor::white()) |
58 | 623k | , m_fillColor(STOFFColor::white()) |
59 | 623k | , m_style(0) |
60 | 623k | , m_position(0) |
61 | 623k | , m_linkName("") |
62 | 623k | , m_filterName("") |
63 | 623k | , m_extra("") |
64 | 623k | { |
65 | 623k | } |
66 | | //! returns true if the brush is empty |
67 | | bool isEmpty() const |
68 | 77.0k | { |
69 | 77.0k | return m_style<=0 || m_style>=11 || m_transparency>=255; |
70 | 77.0k | } |
71 | | //! returns true is the brush has unique color |
72 | | bool hasUniqueColor() const |
73 | 439 | { |
74 | 439 | return m_style==1; |
75 | 439 | } |
76 | | //! try to return a color corresponding to the brush |
77 | | bool getColor(STOFFColor &color) const; |
78 | | //! try to return a pattern corresponding to the brush |
79 | | bool getPattern(STOFFEmbeddedObject &object, STOFFVec2i &sz) const; |
80 | | //! try to read a brush |
81 | | bool read(StarZone &zone, int nVers, long endPos, StarObject &document); |
82 | | //! operator<< |
83 | | friend std::ostream &operator<<(std::ostream &o, StarBrush const &brush); |
84 | | //! the transparency |
85 | | int m_transparency; |
86 | | //! the color |
87 | | STOFFColor m_color; |
88 | | //! the fill color |
89 | | STOFFColor m_fillColor; |
90 | | /** the brush style(pattern): BRUSH_NULL, BRUSH_SOLID, BRUSH_HORZ, BRUSH_VERT, BRUSH_CROSS, |
91 | | BRUSH_DIAGCROSS, BRUSH_UPDIAG, BRUSH_DOWNDIAG, BRUSH_25, BRUSH_50, BRUSH_75, BRUSH_BITMAP */ |
92 | | int m_style; |
93 | | //! the position(none, lt, mt, rt, lm, mm, rm, lb, mb, rb, area, tiled) |
94 | | int m_position; |
95 | | //! the link name |
96 | | librevenge::RVNGString m_linkName; |
97 | | //! the filter name |
98 | | librevenge::RVNGString m_filterName; |
99 | | //! extra data |
100 | | std::string m_extra; |
101 | | }; |
102 | | |
103 | | //! Class to store a graphic |
104 | | class StarGraphic |
105 | | { |
106 | | public: |
107 | | //! constructor |
108 | | StarGraphic() |
109 | 2.07k | : m_object() |
110 | 2.07k | , m_bitmap() |
111 | 2.07k | { |
112 | 2.07k | } |
113 | | //! try to read a graphic, give lastPos if you are sure of the end graphic position |
114 | | bool read(StarZone &zone, long lastPos=-1); |
115 | | //! the embedded object |
116 | | STOFFEmbeddedObject m_object; |
117 | | //! the bitmap |
118 | | std::shared_ptr<StarBitmap> m_bitmap; |
119 | | }; |
120 | | |
121 | | //! Class to store a polygon |
122 | | class StarPolygon |
123 | | { |
124 | | public: |
125 | | //! a structure to keep a point and a flag |
126 | | struct Point { |
127 | | //! constructor |
128 | | explicit Point(STOFFVec2i point=STOFFVec2i(), int flag=0) |
129 | 374k | : m_point(point) |
130 | 374k | , m_flags(flag) |
131 | 374k | { |
132 | 374k | } |
133 | | //! operator<< |
134 | | friend std::ostream &operator<<(std::ostream &o, Point const &point) |
135 | 0 | { |
136 | 0 | o << point.m_point; |
137 | 0 | switch (point.m_flags) { |
138 | 0 | case 0: |
139 | 0 | break; |
140 | 0 | case 1: // smooth |
141 | 0 | o << ":s"; |
142 | 0 | break; |
143 | 0 | case 2: // control |
144 | 0 | o << ":c"; |
145 | 0 | break; |
146 | 0 | case 3: // symetric |
147 | 0 | o << ":S"; |
148 | 0 | break; |
149 | 0 | default: |
150 | 0 | STOFF_DEBUG_MSG(("StarObjectSmallGraphicStruct::StarPolygon::Point::operator<< unexpected flag\n")); |
151 | 0 | o << ":[##" << point.m_flags << "]"; |
152 | 0 | } |
153 | 0 | return o; |
154 | 0 | } |
155 | | //! the point |
156 | | STOFFVec2i m_point; |
157 | | //! the flags |
158 | | int m_flags; |
159 | | }; |
160 | | //! contructor |
161 | | StarPolygon() |
162 | 331k | : m_points() |
163 | 331k | { |
164 | 331k | } |
165 | | //! check if a polygon has special point |
166 | | bool hasSpecialPoints() const |
167 | 27.2k | { |
168 | 59.9k | for (auto const &pt : m_points) { |
169 | 59.9k | if (pt.m_flags) |
170 | 7.05k | return true; |
171 | 59.9k | } |
172 | 20.1k | return false; |
173 | 27.2k | } |
174 | | //! returns true if the polygon is empty |
175 | | bool empty() const |
176 | 38.8k | { |
177 | 38.8k | return m_points.empty(); |
178 | 38.8k | } |
179 | | //! returns true if the polygon is empty |
180 | | size_t size() const |
181 | 85.4k | { |
182 | 85.4k | return m_points.size(); |
183 | 85.4k | } |
184 | | //! add the polygon to a path |
185 | | void addToPath(librevenge::RVNGPropertyListVector &path, bool isClosed, double relUnit, STOFFVec2f const &decal) const; |
186 | | //! convert a path in a string and update the bdbox |
187 | | bool convert(librevenge::RVNGString &path, librevenge::RVNGString &viewbox, double relUnit, STOFFVec2f const &decal) const; |
188 | | //! operator<< |
189 | | friend std::ostream &operator<<(std::ostream &o, StarPolygon const &poly); |
190 | | //! the list of points |
191 | | std::vector<Point> m_points; |
192 | | }; |
193 | | |
194 | | } |
195 | | |
196 | | #endif |
197 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |