Debian Codegraph @

src/lib/MWAWSection.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
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 ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
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 #include <librevenge/librevenge.h>
35
36 #include "libmwaw_internal.hxx"
37 #include "MWAWPosition.hxx"
38
39 #include "MWAWSection.hxx"
40
41 ////////////////////////////////////////////////////////////
42 // Columns
43 ////////////////////////////////////////////////////////////
44 std::ostream &operator<<(std::ostream &o, MWAWSection::Column const &col)
45 {
46 if (col.m_width > 0) o << "w=" << col.m_width << ",";
47 static char const *wh[4]= {"L", "R", "T", "B"};
48 for (int i = 0; i < 4; i++) {
49 if (col.m_margins[i]>0)
50 o << "col" << wh[i] << "=" << col.m_margins[i] << ",";
51 }
52 return o;
53 }
54
55 bool MWAWSection::Column::addTo(librevenge::RVNGPropertyList &propList) const
56 {
57 // The "style:rel-width" is expressed in twips (1440 twips per inch) and includes the left and right Gutter
58 double factor = 1.0;
59 switch (m_widthUnit) {
60 case librevenge::RVNG_POINT:
61 case librevenge::RVNG_INCH:
62 factor = double(MWAWPosition::getScaleFactor(m_widthUnit, librevenge::RVNG_TWIP));
63 break;
64 case librevenge::RVNG_TWIP:
65 break;
66 case librevenge::RVNG_PERCENT:
67 case librevenge::RVNG_GENERIC:
68 case librevenge::RVNG_UNIT_ERROR:
69 #if !defined(__clang__)
70 default:
71 #endif
72 MWAW_DEBUG_MSG(("MWAWSection::Column::addTo: unknown unit\n"));
73 return false;
74 }
75 propList.insert("style:rel-width", m_width * factor, librevenge::RVNG_TWIP);
76 propList.insert("fo:start-indent", m_margins[libmwaw::Left], librevenge::RVNG_INCH);
77 propList.insert("fo:end-indent", m_margins[libmwaw::Right], librevenge::RVNG_INCH);
78 static bool first = true;
79 if (first && (m_margins[libmwaw::Top]>0||m_margins[libmwaw::Bottom]>0)) {
80 first=false;
81 MWAW_DEBUG_MSG(("MWAWSection::Column::addTo: sending before/after margins is not implemented\n"));
82 }
83 return true;
84 }
85
86 ////////////////////////////////////////////////////////////
87 // Section
88 ////////////////////////////////////////////////////////////
89 MWAWSection::~MWAWSection()
90 {
91 }
92
93 std::ostream &operator<<(std::ostream &o, MWAWSection const &sec)
94 {
95 if (sec.m_width>0)
96 o << "width=" << sec.m_width << ",";
97 if (!sec.m_backgroundColor.isWhite())
98 o << "bColor=" << sec.m_backgroundColor << ",";
99 if (sec.m_balanceText)
100 o << "text[balance],";
101 for (size_t c=0; c < sec.m_columns.size(); c++)
102 o << "col" << c << "=[" << sec.m_columns[c] << "],";
103 if (sec.m_columnSeparator.m_style != MWAWBorder::None &&
104 sec.m_columnSeparator.m_width > 0)
105 o << "colSep=[" << sec.m_columnSeparator << "],";
106 return o;
107 }
108
109 void MWAWSection::setColumns(int num, double width, librevenge::RVNGUnit widthUnit, double colSep)
110 {
111 if (num<0) {
112 MWAW_DEBUG_MSG(("MWAWSection::setColumns: called with negative number of column\n"));
113 num=1;
114 }
115 else if (num > 1 && width<=0) {
116 MWAW_DEBUG_MSG(("MWAWSection::setColumns: called without width\n"));
117 num=1;
118 }
119 m_columns.resize(0);
120 if (num==1 && (width<=0 || colSep<=0))
121 return;
122
123 Column column;
124 column.m_width=width;
125 column.m_widthUnit = widthUnit;
126 column.m_margins[libmwaw::Left] = column.m_margins[libmwaw::Right] = colSep/2.;
127 m_columns.resize(size_t(num), column);
128 }
129
130 void MWAWSection::addTo(librevenge::RVNGPropertyList &propList) const
131 {
132 propList.insert("fo:margin-left", 0.0, librevenge::RVNG_INCH);
133 propList.insert("fo:margin-right", 0.0, librevenge::RVNG_INCH);
134 if (m_columns.size() > 1)
135 propList.insert("text:dont-balance-text-columns", !m_balanceText);
136 if (!m_backgroundColor.isWhite())
137 propList.insert("fo:background-color", m_backgroundColor.str().c_str());
138 if (m_columnSeparator.m_style != MWAWBorder::None &&
139 m_columnSeparator.m_width > 0) {
140 propList.insert("librevenge:colsep-width", m_columnSeparator.m_width, librevenge::RVNG_POINT);
141 propList.insert("librevenge:colsep-color", m_columnSeparator.m_color.str().c_str());
142 propList.insert("librevenge:colsep-height", "100%");
143 propList.insert("librevenge:colsep-vertical-align", "middle");
144 }
145 }
146
147 void MWAWSection::addColumnsTo(librevenge::RVNGPropertyListVector &propVec) const
148 {
149 if (m_columns.empty()) return;
150 for (auto const &column : m_columns) {
151 librevenge::RVNGPropertyList propList;
152 if (column.addTo(propList))
153 propVec.append(propList);
154 }
155 }
156
157 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: