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