Coverage Report

Created: 2026-10-28 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/MWAWParagraph.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
/* 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
#ifndef MWAW_PARAGRAPH
35
#  define MWAW_PARAGRAPH
36
37
#include <iostream>
38
#include <vector>
39
40
#include <librevenge/librevenge.h>
41
42
#include "libmwaw_internal.hxx"
43
#include "MWAWList.hxx"
44
45
/** class to store a tab use by MWAWParagraph */
46
struct MWAWTabStop {
47
  //! the tab alignment
48
  enum Alignment { LEFT, RIGHT, CENTER, DECIMAL, BAR };
49
  //! constructor
50
  explicit MWAWTabStop(double position = 0.0, Alignment alignment = LEFT, uint16_t leaderCharacter='\0', uint16_t decimalCharacter = '.')
51
14.7M
    : m_position(position)
52
14.7M
    , m_alignment(alignment)
53
14.7M
    , m_leaderCharacter(leaderCharacter)
54
14.7M
    , m_decimalCharacter(decimalCharacter)
55
14.7M
  {
56
14.7M
  }
57
  //! add a tab to the propList
58
  void addTo(librevenge::RVNGPropertyListVector &propList, double decalX=0.0) const;
59
  //! operator==
60
  bool operator==(MWAWTabStop const &tabs) const
61
0
  {
62
0
    return cmp(tabs)==0;
63
0
  }
64
  //! operator!=
65
  bool operator!=(MWAWTabStop const &tabs) const
66
0
  {
67
0
    return cmp(tabs)!=0;
68
0
  }
69
  //! operator <<
70
  friend std::ostream &operator<<(std::ostream &o, MWAWTabStop const &ft);
71
  //! a comparison function
72
  int cmp(MWAWTabStop const &tabs) const;
73
  //! the tab position
74
  double m_position;
75
  //! the alignment ( left, center, ...)
76
  Alignment m_alignment;
77
  //! the leader char
78
  uint16_t m_leaderCharacter;
79
  //! the decimal char
80
  uint16_t m_decimalCharacter;
81
};
82
83
//! class to store the paragraph properties
84
class MWAWParagraph
85
{
86
public:
87
  /** some bit use to defined the break status */
88
  enum { NoBreakBit = 0x1, NoBreakWithNextBit=0x2 };
89
  /** an enum used to defined the paragraph justification: left, center, right, full ... */
90
  enum Justification { JustificationLeft, JustificationFull, JustificationCenter,
91
                       JustificationRight, JustificationFullAllLines
92
                     };
93
  /** the line spacing type: fixed or at least */
94
  enum LineSpacingType { Fixed, AtLeast};
95
96
  //! constructor
97
  MWAWParagraph();
98
121M
  MWAWParagraph(MWAWParagraph const &)=default;
99
9.09M
  MWAWParagraph &operator=(MWAWParagraph const &)=default;
100
2.26M
  MWAWParagraph &operator=(MWAWParagraph &&)=default;
101
  //! destructor
102
  virtual ~MWAWParagraph();
103
  //! operator==
104
  bool operator==(MWAWParagraph const &p) const
105
6.35M
  {
106
6.35M
    return cmp(p)==0;
107
6.35M
  }
108
  //! operator!=
109
  bool operator!=(MWAWParagraph const &p) const
110
0
  {
111
0
    return cmp(p)!=0;
112
0
  }
113
  //! a comparison function
114
  int cmp(MWAWParagraph const &p) const;
115
  //! return the paragraph margin width (in inches)
116
  double getMarginsWidth() const;
117
  //! check if the paragraph has some borders
118
  bool hasBorders() const;
119
  //! check if the paragraph has different borders
120
  bool hasDifferentBorders() const;
121
  //! a function used to resize the borders list ( adding empty borders if needed )
122
  void resizeBorders(size_t newSize)
123
791k
  {
124
791k
    MWAWBorder empty;
125
791k
    empty.m_style=MWAWBorder::None;
126
791k
    m_borders.resize(newSize, MWAWVariable<MWAWBorder>(empty));
127
791k
  }
128
  //! set the interline
129
  void setInterline(double value, librevenge::RVNGUnit unit, LineSpacingType type=Fixed)
130
2.91M
  {
131
2.91M
    m_spacings[0]=value;
132
2.91M
    m_spacingsInterlineUnit=unit;
133
2.91M
    m_spacingsInterlineType=type;
134
2.91M
  }
135
  //! add to the propList
136
  void addTo(librevenge::RVNGPropertyList &propList, bool inTable) const;
137
138
  //! insert the set values of para in the actual paragraph
139
  void insert(MWAWParagraph const &para);
140
  //! operator <<
141
  friend std::ostream &operator<<(std::ostream &o, MWAWParagraph const &ft);
142
143
  /** the margins
144
   *
145
   * - 0: first line left margin
146
   * - 1: left margin
147
   * - 2: right margin*/
148
  MWAWVariable<double> m_margins[3]; // 0: first line left, 1: left, 2: right
149
  /** the margins INCH, ... */
150
  MWAWVariable<librevenge::RVNGUnit> m_marginsUnit;
151
  /** the line spacing
152
   *
153
   * - 0: interline
154
   * - 1: before
155
   * - 2: after */
156
  MWAWVariable<double> m_spacings[3]; // 0: interline, 1: before, 2: after
157
  /** the interline unit PERCENT or INCH, ... */
158
  MWAWVariable<librevenge::RVNGUnit> m_spacingsInterlineUnit;
159
  /** the interline type: fixed, atLeast, ... */
160
  MWAWVariable<LineSpacingType> m_spacingsInterlineType;
161
  //! the tabulations
162
  MWAWVariable<std::vector<MWAWTabStop> > m_tabs;
163
  //! true if the tabs are relative to left margin, false if there are relative to the page margin (default)
164
  MWAWVariable<bool> m_tabsRelativeToLeftMargin;
165
166
  /** the justification */
167
  MWAWVariable<Justification> m_justify;
168
  /** a list of bits: 0x1 (unbreakable), 0x2 (do not break after) */
169
  MWAWVariable<int> m_breakStatus; // BITS: 1: unbreakable, 2: dont break after
170
  //! the writing mode
171
  MWAWVariable<libmwaw::WritingMode> m_writingMode;
172
173
  /** the actual level index */
174
  MWAWVariable<int> m_listLevelIndex;
175
  /** the list id (if know ) */
176
  MWAWVariable<int> m_listId;
177
  /** the list start value (if set ) */
178
  MWAWVariable<int> m_listStartValue;
179
  /** the actual level */
180
  MWAWVariable<MWAWListLevel> m_listLevel;
181
182
  //! the background color
183
  MWAWVariable<MWAWColor> m_backgroundColor;
184
185
  //! list of border ( order MWAWBorder::Pos)
186
  std::vector<MWAWVariable<MWAWBorder> > m_borders;
187
  /** the drop number character */
188
  MWAWVariable<int> m_dropNumCharacters;
189
  /** the drop number of lines */
190
  MWAWVariable<int> m_dropNumLines;
191
192
  //! the style name
193
  std::string m_styleName;
194
  //! a string to store some errors
195
  std::string m_extra;
196
};
197
#endif
198
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: