Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* libmspub
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 Brennan Vincent <brennanv@email.arizona.edu>
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
24 : * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
25 : * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include "Fill.h"
30 : #include "libmspub_utils.h"
31 : #include "MSPUBCollector.h"
32 :
33 : using namespace libmspub;
34 :
35 0 : Fill::Fill(const MSPUBCollector *owner) : m_owner(owner)
36 : {
37 0 : }
38 :
39 0 : ImgFill::ImgFill(unsigned imgIndex, const MSPUBCollector *owner, bool isTexture) : Fill(owner), m_imgIndex(imgIndex), m_isTexture(isTexture)
40 : {
41 0 : }
42 :
43 0 : WPXPropertyListVector ImgFill::getProperties(WPXPropertyList *out) const
44 : {
45 0 : out->insert("draw:fill", "bitmap");
46 0 : if (m_imgIndex <= m_owner->m_images.size())
47 : {
48 0 : const std::pair<ImgType, WPXBinaryData> &img = m_owner->m_images[m_imgIndex - 1];
49 0 : out->insert("libwpg:mime-type", mimeByImgType(img.first));
50 0 : out->insert("draw:fill-image", img.second.getBase64Data());
51 0 : out->insert("draw:fill-image-ref-point", "top-left");
52 0 : if (! m_isTexture)
53 : {
54 0 : out->insert("style:repeat", "stretch");
55 : }
56 : }
57 0 : return WPXPropertyListVector();
58 : }
59 :
60 0 : PatternFill::PatternFill(unsigned imgIndex, const MSPUBCollector *owner, ColorReference fg, ColorReference bg) : ImgFill(imgIndex, owner, true), m_fg(fg), m_bg(bg)
61 : {
62 0 : }
63 :
64 0 : WPXPropertyListVector PatternFill::getProperties(WPXPropertyList *out) const
65 : {
66 0 : Color fgColor = m_fg.getFinalColor(m_owner->m_paletteColors);
67 0 : Color bgColor = m_bg.getFinalColor(m_owner->m_paletteColors);
68 0 : out->insert("draw:fill", "bitmap");
69 0 : if (m_imgIndex <= m_owner->m_images.size())
70 : {
71 0 : const std::pair<ImgType, WPXBinaryData> &img = m_owner->m_images[m_imgIndex - 1];
72 0 : const ImgType &type = img.first;
73 0 : const WPXBinaryData *data = &img.second;
74 : // fix broken MSPUB DIB by putting in correct fg and bg colors
75 0 : WPXBinaryData fixedImg;
76 0 : if (type == DIB && data->size() >= 0x36 + 8)
77 : {
78 0 : fixedImg.append(data->getDataBuffer(), 0x36);
79 0 : fixedImg.append(bgColor.b);
80 0 : fixedImg.append(bgColor.g);
81 0 : fixedImg.append(bgColor.r);
82 0 : fixedImg.append('\0');
83 0 : fixedImg.append(fgColor.b);
84 0 : fixedImg.append(fgColor.g);
85 0 : fixedImg.append(fgColor.r);
86 0 : fixedImg.append('\0');
87 0 : fixedImg.append(data->getDataBuffer() + 0x36 + 8, data->size() - 0x36 - 8);
88 0 : data = &fixedImg;
89 : }
90 0 : out->insert("libwpg:mime-type", mimeByImgType(type));
91 0 : out->insert("draw:fill-image", data->getBase64Data());
92 0 : out->insert("draw:fill-image-ref-point", "top-left");
93 : }
94 0 : return WPXPropertyListVector();
95 : }
96 :
97 0 : SolidFill::SolidFill(ColorReference color, double opacity, const MSPUBCollector *owner) : Fill(owner), m_color(color), m_opacity(opacity)
98 : {
99 0 : }
100 :
101 0 : WPXPropertyListVector SolidFill::getProperties(WPXPropertyList *out) const
102 : {
103 0 : Color fillColor = m_color.getFinalColor(m_owner->m_paletteColors);
104 0 : out->insert("draw:fill", "solid");
105 0 : out->insert("draw:fill-color", MSPUBCollector::getColorString(fillColor));
106 0 : WPXString val;
107 0 : val.sprintf("%d%%", (int)(m_opacity * 100));
108 0 : out->insert("draw:opacity", val);
109 0 : out->insert("svg:fill-rule", "nonzero");
110 0 : return WPXPropertyListVector();
111 : }
112 :
113 0 : GradientFill::GradientFill(const MSPUBCollector *owner, double angle) : Fill(owner), m_stops(), m_angle(angle)
114 : {
115 0 : }
116 :
117 0 : void GradientFill::addColor(ColorReference c, unsigned offsetPercent, double opacity)
118 : {
119 0 : m_stops.push_back(StopInfo(c, offsetPercent, opacity));
120 0 : }
121 :
122 0 : WPXPropertyListVector GradientFill::getProperties(WPXPropertyList *out) const
123 : {
124 0 : WPXPropertyListVector ret;
125 0 : out->insert("draw:fill", "gradient");
126 0 : out->insert("svg:fill-rule", "nonzero");
127 0 : out->insert("draw:angle", -m_angle); // draw:angle is clockwise in odf format
128 0 : for (unsigned i = 0; i < m_stops.size(); ++i)
129 : {
130 0 : Color c = m_stops[i].m_colorReference.getFinalColor(m_owner->m_paletteColors);
131 0 : WPXPropertyList stopProps;
132 0 : WPXString sValue;
133 0 : sValue.sprintf("%d%%", m_stops[i].m_offsetPercent);
134 0 : stopProps.insert("svg:offset", sValue);
135 0 : stopProps.insert("svg:stop-color", MSPUBCollector::getColorString(c));
136 0 : sValue.sprintf("%d%%", (int)(m_stops[i].m_opacity * 100));
137 0 : stopProps.insert("svg:stop-opacity", sValue);
138 0 : ret.append(stopProps);
139 0 : }
140 0 : return ret;
141 0 : }
142 :
143 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|