Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* libcdr
3 : * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
17 : * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
18 : *
19 : *
20 : * All Rights Reserved.
21 : *
22 : * For minor contributions see the git repository.
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
26 : * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
27 : * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
28 : * instead of those above.
29 : */
30 :
31 : #include "CDRTypes.h"
32 : #include "CDRPath.h"
33 : #include "libcdr_utils.h"
34 :
35 0 : void libcdr::CDRPolygon::create(libcdr::CDRPath &path) const
36 : {
37 0 : libcdr::CDRPath tmpPath(path);
38 0 : double step = 2*M_PI / (double)m_numAngles;
39 0 : if (m_numAngles % m_nextPoint)
40 : {
41 0 : libcdr::CDRTransform tmpTrafo(cos(m_nextPoint*step), sin(m_nextPoint*step), 0.0, -sin(m_nextPoint*step), cos(m_nextPoint*step), 0.0);
42 0 : for (unsigned i = 1; i < m_numAngles; ++i)
43 : {
44 0 : tmpPath.transform(tmpTrafo);
45 0 : path.appendPath(tmpPath);
46 : }
47 : }
48 : else
49 : {
50 0 : libcdr::CDRTransform tmpTrafo(cos(m_nextPoint*step), sin(m_nextPoint*step), 0.0, -sin(m_nextPoint*step), cos(m_nextPoint*step), 0.0);
51 0 : libcdr::CDRTransform tmpShift(cos(step), sin(step), 0.0, -sin(step), cos(step), 0.0);
52 0 : for (unsigned i = 0; i < m_nextPoint; ++i)
53 : {
54 0 : if (i)
55 : {
56 0 : tmpPath.transform(tmpShift);
57 0 : path.appendPath(tmpPath);
58 : }
59 0 : for (unsigned j=1; j < m_numAngles / m_nextPoint; ++j)
60 : {
61 0 : tmpPath.transform(tmpTrafo);
62 0 : path.appendPath(tmpPath);
63 : }
64 0 : path.appendClosePath();
65 : }
66 : }
67 0 : path.appendClosePath();
68 0 : libcdr::CDRTransform trafo(m_rx, 0.0, m_cx, 0.0, m_ry, m_cy);
69 0 : path.transform(trafo);
70 0 : }
71 :
72 0 : void libcdr::CDRSplineData::create(libcdr::CDRPath &path) const
73 : {
74 0 : if (points.empty() || knotVector.empty())
75 0 : return;
76 0 : path.appendMoveTo(points[0].first, points[0].second);
77 0 : std::vector<std::pair<double, double> > tmpPoints;
78 0 : tmpPoints.push_back(points[0]);
79 0 : for (unsigned i = 1; i<points.size() && i<knotVector.size(); ++i)
80 : {
81 0 : tmpPoints.push_back(points[i]);
82 0 : if (knotVector[i])
83 : {
84 0 : if (tmpPoints.size() == 2)
85 0 : path.appendLineTo(tmpPoints[1].first, tmpPoints[1].second);
86 0 : else if (tmpPoints.size() == 3)
87 0 : path.appendQuadraticBezierTo(tmpPoints[1].first, tmpPoints[1].second,
88 0 : tmpPoints[2].first, tmpPoints[3].second);
89 : else
90 0 : path.appendSplineTo(tmpPoints);
91 0 : tmpPoints.clear();
92 0 : tmpPoints.push_back(points[i]);
93 : }
94 : }
95 0 : if (tmpPoints.size() == 2)
96 0 : path.appendLineTo(tmpPoints[1].first, tmpPoints[1].second);
97 0 : else if (tmpPoints.size() == 3)
98 0 : path.appendQuadraticBezierTo(tmpPoints[1].first, tmpPoints[1].second,
99 0 : tmpPoints[2].first, tmpPoints[3].second);
100 0 : else if (tmpPoints.size() > 3)
101 0 : path.appendSplineTo(tmpPoints);
102 : }
103 :
104 0 : libcdr::CDRCMYKColor::CDRCMYKColor(unsigned colorValue, bool percentage)
105 : : c((double)(colorValue & 0xff) / (percentage ? 100.0 : 255.0)),
106 : m((double)((colorValue & 0xff00) >> 8) / (percentage ? 100.0 : 255.0)),
107 : y((double)((colorValue & 0xff0000) >> 16) / (percentage ? 100.0 : 255.0)),
108 0 : k((double)((colorValue & 0xff000000) >> 24) / (percentage ? 100.0 : 255.0))
109 : {
110 0 : }
111 :
112 0 : void libcdr::CDRCMYKColor::applyTint(double tint)
113 : {
114 0 : if (tint < 0.0)
115 0 : tint = 0.0;
116 0 : if (tint > 1.0)
117 0 : tint = 1.0;
118 0 : c *= tint;
119 0 : m *= tint;
120 0 : y *= tint;
121 0 : k *= tint;
122 0 : }
123 :
124 0 : unsigned libcdr::CDRCMYKColor::getColorValue() const
125 : {
126 0 : return 0;
127 : }
128 :
129 :
130 0 : libcdr::CDRRGBColor::CDRRGBColor(unsigned colorValue)
131 : : r((double)(colorValue & 0xff) / 255.0),
132 : g((double)((colorValue & 0xff00) >> 8) / 255.0),
133 0 : b((double)((colorValue & 0xff0000) >> 16) / 255.0)
134 : {
135 0 : }
136 :
137 0 : void libcdr::CDRRGBColor::applyTint(double tint)
138 : {
139 0 : if (tint < 0.0)
140 0 : tint = 0.0;
141 0 : if (tint > 1.0)
142 0 : tint = 1.0;
143 0 : r = 1.0 + r*tint - tint;
144 0 : g = 1.0 + g*tint - tint;
145 0 : b = 1.0 + b*tint - tint;
146 0 : }
147 :
148 0 : unsigned libcdr::CDRRGBColor::getColorValue() const
149 : {
150 0 : return 0;
151 : }
152 :
153 :
154 0 : libcdr::CDRLab2Color::CDRLab2Color(unsigned colorValue)
155 : : L((double)(colorValue & 0xff)*100.0/255.0),
156 : a((double)(signed char)((colorValue & 0xff00) >> 8)),
157 0 : b((double)(signed char)((colorValue & 0xff0000) >> 16))
158 : {
159 0 : }
160 :
161 0 : void libcdr::CDRLab2Color::applyTint(double tint)
162 : {
163 0 : if (tint < 0.0)
164 0 : tint = 0.0;
165 0 : if (tint > 1.0)
166 0 : tint = 1.0;
167 0 : L = (1.0 - tint)*100.0 + tint*L;
168 0 : a *= tint;
169 0 : b *= tint;
170 0 : }
171 :
172 0 : unsigned libcdr::CDRLab2Color::getColorValue() const
173 : {
174 0 : return 0;
175 : }
176 :
177 :
178 0 : libcdr::CDRLab4Color::CDRLab4Color(unsigned colorValue)
179 : : L((double)(colorValue & 0xff)*100.0/255.0),
180 : a((double)((signed char)(((colorValue & 0xff00) >> 8) - 0x80))),
181 0 : b((double)((signed char)(((colorValue & 0xff0000) >> 16) - 0x80)))
182 : {
183 0 : }
184 :
185 0 : void libcdr::CDRLab4Color::applyTint(double tint)
186 : {
187 0 : if (tint < 0.0)
188 0 : tint = 0.0;
189 0 : if (tint > 1.0)
190 0 : tint = 1.0;
191 0 : L = (1.0 - tint)*100.0 + tint*L;
192 0 : a *= tint;
193 0 : b *= tint;
194 0 : }
195 :
196 0 : unsigned libcdr::CDRLab4Color::getColorValue() const
197 : {
198 0 : return 0;
199 : }
200 :
201 :
202 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|