Scribus
Open source desktop publishing at your fingertips
paragraphstyle.h
1 /*
2  For general Scribus (>=1.3.2) copyright and licensing information please refer
3  to the COPYING file provided with the program. Following this notice may exist
4  a copyright and/or license notice that predates the release of Scribus 1.3.2
5  for which a new license (GPL+exception) is in place.
6  */
7 /***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #ifndef PARAGRAPHSTYLE_H
17 #define PARAGRAPHSTYLE_H
18 
19 #include "style.h"
20 #include "charstyle.h"
21 #include "styles/stylecontextproxy.h"
22 
23 
24 class ResourceCollection;
25 
26 
27 class SCRIBUS_API ParagraphStyle : public Style
28 {
29 public:
30  enum LineSpacingMode {
31  FixedLineSpacing = 0,
32  AutomaticLineSpacing = 1,
33  BaselineGridLineSpacing = 2
34  };
35  enum AlignmentType {
36  Leftaligned = 0,
37  Centered = 1,
38  Rightaligned = 2,
39  Justified = 3,
40  Extended = 4
41  };
42  enum OpticalMarginType {
43  OM_None = 0,
44  OM_LeftProtruding = 1,
45  OM_RightProtruding = 2,
46  OM_LeftHangingPunct = 4,
47  OM_RightHangingPunct = 8,
48  OM_Default = OM_RightProtruding + OM_LeftHangingPunct + OM_RightHangingPunct
49  };
50  enum HyphenationMode {
51  NoHyphenation = 0,
52  ManualHyphenation = 1,
53  AutomaticHyphenation = 2
54  };
55  struct TabRecord
56  {
57  qreal tabPosition;
58  int tabType;
59  QChar tabFillChar;
60  bool operator==(const TabRecord& other) const;
61  bool operator<(const TabRecord& other) const { return tabPosition < other.tabPosition; }
62  bool operator<=(const TabRecord& other) const { return tabPosition <= other.tabPosition; }
63  bool operator>(const TabRecord& other) const { return tabPosition > other.tabPosition; }
64  bool operator>=(const TabRecord& other) const { return tabPosition >= other.tabPosition; }
65  };
66 
68  ParagraphStyle(const ParagraphStyle& other);
69  ParagraphStyle& operator=(const ParagraphStyle& other);
70  ~ParagraphStyle();
71 
72  static const Xml_string saxxDefaultElem;
73  static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
74 
75  virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
76  virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
77 
78 
79  void getNamedResources(ResourceCollection& lists) const;
80  void replaceNamedResources(ResourceCollection& newNames);
81 
82  QString displayName() const;
83 
84  void setContext(const StyleContext* context);
85  void update(const StyleContext*);
86 
87  bool equiv(const Style& other) const;
88 
89  void applyStyle(const ParagraphStyle& other);
90  void eraseStyle(const ParagraphStyle& other);
91  void setStyle(const ParagraphStyle& other);
92  void erase() { eraseStyle(*this); }
93 
94  StyleContext* charStyleContext() { return & cstyleContext; }
95  const StyleContext* charStyleContext() const { return & cstyleContext; }
96  CharStyle & charStyle() { return cstyle; }
97  const CharStyle& charStyle() const { return cstyle; }
101  void breakImplicitCharStyleInheritance(bool val = true);
106  void repairImplicitCharStyleInheritance();
107 
110 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
111  const attr_TYPE &attr_GETTER() const { validate(); return m_##attr_NAME; }
112 #include "paragraphstyle.attrdefs.cxx"
113 #undef ATTRDEF
114 
117 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
118  void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
119 #include "paragraphstyle.attrdefs.cxx"
120 #undef ATTRDEF
121  void appendTabValue(const TabRecord& tab) { validate(); m_TabValues.append(tab); inh_TabValues = false; }
122 
123 
126 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
127  void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
128 #include "paragraphstyle.attrdefs.cxx"
129 #undef ATTRDEF
130 
132 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
133  bool isInh##attr_NAME() const { return inh_##attr_NAME; }
134 #include "paragraphstyle.attrdefs.cxx"
135 #undef ATTRDEF
136 
137 
139 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
140  bool isDef##attr_NAME() const { \
141  if ( !inh_##attr_NAME ) return true; \
142  const ParagraphStyle * par = dynamic_cast<const ParagraphStyle*>(parentStyle()); \
143  return par && par->isDef##attr_NAME(); \
144  }
145 #include "paragraphstyle.attrdefs.cxx"
146 #undef ATTRDEF
147 
148 
149 private:
150 
151  // member declarations:
152  StyleContextProxy cstyleContext;
153  bool cstyleContextIsInh;
154  CharStyle cstyle;
155 
156 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
157  attr_TYPE m_##attr_NAME; \
158  bool inh_##attr_NAME;
159 #include "paragraphstyle.attrdefs.cxx"
160 #undef ATTRDEF
161 
162 };
163 
164 #endif
Definition: charstyle.h:78
virtual bool equiv(const Style &other) const =0
Definition: stylecontext.h:35
Definition: saxhandler.h:21
Definition: stylecontextproxy.h:33
virtual void saxx(SaxHandler &handler) const
Definition: paragraphstyle.h:76
virtual void update(const StyleContext *b=NULL)
Definition: style.cpp:54
Definition: paragraphstyle.h:55
Definition: paragraphstyle.h:27
bool operator<=(Point const &a, Point const &b)
Definition: point.h:156
void applyStyle(const Style &other)
Definition: style.h:145
Definition: style.h:37
void eraseStyle(const Style &other)
Definition: style.h:153
static const Xml_string saxxDefaultElem
Definition: saxio.h:40
void erase()
Definition: paragraphstyle.h:92
Definition: digester.h:100
virtual void saxx(SaxHandler &, const Xml_string &) const =0
void validate() const
Definition: style.h:113
Definition: resourcecollection.h:41