lib

contextstyle.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef CONTEXTSTYLE_H
22#define CONTEXTSTYLE_H
23
24//TQt Include
25#include <tqcolor.h>
26#include <tqfont.h>
27#include <tqstring.h>
28#include <tqstringlist.h>
29#include <tqvaluestack.h>
30
31//KDE Include
32#include <tdeconfig.h>
33#include <KoTextZoomHandler.h>
34
35//Formula include
36#include "kformuladefs.h"
37
38
39KFORMULA_NAMESPACE_BEGIN
40
41class FontStyle;
42class SymbolTable;
43
44
53class ContextStyle : public KoTextZoomHandler
54{
55public:
56
57 enum Alignment { left, center, right };
58
71 enum TextStyle {
72 displayStyle = 0,
73 textStyle = 1,
74 scriptStyle = 2,
75 scriptScriptStyle = 3
76 };
77
78 enum IndexStyle {normal, cramped};
79
85
89 void init( bool init = true );
90
96 void readConfig( TDEConfig* config, bool init = true );
97
98 bool edit() const { return m_edit; }
99 void setEdit( bool e ) { m_edit = e; }
100
104 const SymbolTable& symbolTable() const;
105
106 const FontStyle& fontStyle() const { return *m_fontStyle; }
107
108
109 void setZoomAndResolution( int zoom, int dpiX, int dpiY );
110
115 bool setZoomAndResolution( int zoom, double zoomX, double zoomY, bool updateViews, bool forPrint );
116
117 bool syntaxHighlighting() const { return m_syntaxHighlighting; }
118 void setSyntaxHighlighting( bool highlight ) { m_syntaxHighlighting = highlight; }
119
120 TQColor getDefaultColor() const { return defaultColor; }
121 TQColor getNumberColorPlain() const { return numberColor; }
122 TQColor getOperatorColorPlain() const { return operatorColor; }
123 TQColor getErrorColorPlain() const { return errorColor; }
124 TQColor getEmptyColorPlain() const { return emptyColor; }
125 TQColor getHelpColorPlain() const { return helpColor; }
126 TQColor getNumberColor() const;
127 TQColor getOperatorColor() const;
128 TQColor getErrorColor() const;
129 TQColor getEmptyColor() const;
130 TQColor getHelpColor() const;
131
132 void setDefaultColor( const TQColor& );
133 void setNumberColor( const TQColor& );
134 void setOperatorColor( const TQColor& );
135 void setErrorColor( const TQColor& );
136 void setEmptyColor( const TQColor& );
137 void setHelpColor( const TQColor& );
138
139 TQString getFontStyle() const { return m_fontStyleName; }
140 void setFontStyle( const TQString& fontStyle, bool init = true );
141
142 TQFont getMathFont() const { return mathFont; }
143 TQFont getBracketFont() const { return bracketFont; }
144 TQFont getDefaultFont() const { return defaultFont; }
145 TQFont getNameFont() const { return nameFont; }
146 TQFont getNumberFont() const { return numberFont; }
147 TQFont getOperatorFont() const { return operatorFont; }
148 TQFont getSymbolFont() const { return symbolFont; }
149
150 void setMathFont( TQFont f ) { defaultFont = f; }
151 void setBracketFont( TQFont f ) { bracketFont = f; }
152 void setDefaultFont( TQFont f ) { defaultFont = f; }
153 void setNameFont( TQFont f ) { nameFont = f; }
154 void setNumberFont( TQFont f ) { numberFont = f; }
155 void setOperatorFont( TQFont f ) { operatorFont = f; }
156
157 //const TQStringList& requestedFonts() const;
158 //void setRequestedFonts( const TQStringList& list );
159
160 double getReductionFactor( TextStyle tstyle ) const;
161
162 luPt getBaseSize() const;
163 int baseSize() const { return m_baseSize; }
164 void setBaseSize( int pointSize );
165 void setSizeFactor( double factor );
166
167 TextStyle getBaseTextStyle() const { return m_baseTextStyle; }
168 bool isScript( TextStyle tstyle ) const { return ( tstyle == scriptStyle ) ||
169 ( tstyle == scriptScriptStyle ); }
170
174 luPixel getSpace( TextStyle tstyle, SpaceWidth space, double factor ) const;
175 luPixel getThinSpace( TextStyle tstyle, double factor ) const;
176 luPixel getMediumSpace( TextStyle tstyle, double factor ) const;
177 luPixel getThickSpace( TextStyle tstyle, double factor ) const;
178 luPixel getQuadSpace( TextStyle tstyle, double factor ) const;
179
180 luPixel axisHeight( TextStyle tstyle, double factor ) const;
181
185 luPt getAdjustedSize( TextStyle tstyle, double factor ) const;
186
190 luPixel getLineWidth( double factor ) const;
191
192 luPixel getEmptyRectWidth( double factor ) const;
193 luPixel getEmptyRectHeight( double factor ) const;
194
195 Alignment getMatrixAlignment() const { return center; }
196
197 bool getCenterSymbol() const { return centerSymbol; }
198
206
214
224 IndexStyle convertIndexStyleUpper( IndexStyle istyle ) const {
225 return istyle; }
226
227
237 IndexStyle convertIndexStyleLower( IndexStyle /*istyle*/ ) const {
238 return cramped; }
239
240private:
241
242 void setup();
243
244 struct TextStyleValues {
245
246 void setup( double reduction ) { reductionFactor = reduction; }
247
248 luPt thinSpace( luPt quad ) const { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )/6. ); }
249 luPt mediumSpace( luPt quad ) const { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*2./9. ); }
250 luPt thickSpace( luPt quad ) const { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*5./18. ); }
251 luPt quadSpace( luPt quad ) const { return quad; }
252
253 luPixel axisHeight( luPixel height ) const { return static_cast<luPixel>( reductionFactor*height ); }
254 double reductionFactor;
255 };
256
257 TextStyleValues textStyleValues[ 4 ];
258
259 TQFont mathFont;
260 TQFont bracketFont;
261 TQFont defaultFont;
262 TQFont nameFont;
263 TQFont numberFont;
264 TQFont operatorFont;
265 TQFont symbolFont;
266
267 //TQStringList m_requestedFonts;
268
269 TQColor defaultColor;
270 TQColor numberColor;
271 TQColor operatorColor;
272 TQColor errorColor;
273 TQColor emptyColor;
274 TQColor helpColor;
275
280 bool linearMovement;
281
285 int m_baseSize;
286
291 double m_sizeFactor;
292
296 TextStyle m_baseTextStyle;
297
301 pt lineWidth;
302
306 luPt quad;
307
311 luPixel m_axisHeight;
312
317 bool centerSymbol;
318
322 bool m_syntaxHighlighting;
323
327 bool m_edit;
328
332 //SymbolTable table;
333
334 FontStyle* m_fontStyle;
335 TQString m_fontStyleName;
336};
337
338// Section 3.3.4.2, default values
339const double scriptsizemultiplier = 0.71;
340const double scriptminsize = 8;
341const double veryverythinmathspace = 0.0555556;
342const double verythinmathspace = 0.111111;
343const double thinmathspace = 0.166667;
344const double mediummathspace = 0.222222;
345const double thickmathspace = 0.277778;
346const double verythickmathspace = 0.333333;
347const double veryverythickmathspace = 0.388889;
348
349class StyleAttributes {
350 public:
351 double sizeFactor() const ;
352 bool customMathVariant() const ;
353 CharStyle charStyle() const ;
354 CharFamily charFamily() const ;
355 TQColor color() const ;
356 TQColor background() const ;
357 TQFont font() const ;
358 bool fontWeight() const ;
359 bool customFontWeight() const ;
360 bool fontStyle() const ;
361 bool customFontStyle() const ;
362 bool customFont() const ;
363
364 int scriptLevel() const ;
365 double scriptSizeMultiplier() const ;
366 double scriptMinSize() const ;
367 double veryVeryThinMathSpace() const ;
368 double veryThinMathSpace() const ;
369 double thinMathSpace() const ;
370 double mediumMathSpace() const ;
371 double thickMathSpace() const ;
372 double veryThickMathSpace() const ;
373 double veryVeryThickMathSpace() const ;
374 bool displayStyle() const ;
375 bool customDisplayStyle() const ;
376
377 double getSpace( SizeType type, double length ) const ;
378
379 void setSizeFactor( double s ) { m_size.push( s ); }
380 void setCustomMathVariant( bool cmv ) { m_customMathVariant.push( cmv ); }
381 void setCharStyle( CharStyle cs ) { m_charStyle.push( cs ); }
382 void setCharFamily( CharFamily cf ) { m_charFamily.push( cf ); }
383 void setColor( const TQColor& c ) { m_color.push( c ); }
384 void setBackground( const TQColor& bg ) { m_background.push( bg ); }
385 void setFont( const TQFont& f ) { m_font.push( f ); }
386 void setCustomFont( bool cf ) { m_customFontFamily.push ( cf ); }
387 void setCustomFontWeight( bool cfw ) { m_customFontWeight.push( cfw ); }
388 void setFontWeight( bool fw ) { m_fontWeight.push( fw ); }
389 void setCustomFontStyle( bool cfs ) { m_customFontStyle.push( cfs ); }
390 void setFontStyle( bool fs ) { m_fontStyle.push( fs ); }
391
392 void setScriptLevel( int s ) { m_scriptLevel.push( s ); }
393 void setScriptSizeMultiplier( double s ) { m_scriptSizeMultiplier.push( s ); }
394 void setScriptMinSize( double s ) { m_scriptMinSize.push( s ); }
395 void setVeryVeryThinMathSpace( double s ) { m_veryVeryThinMathSpace.push( s ); }
396 void setVeryThinMathSpace( double s ) { m_veryThinMathSpace.push( s ); }
397 void setThinMathSpace( double s ) { m_thinMathSpace.push( s ); }
398 void setMediumMathSpace( double s ) { m_mediumMathSpace.push( s ); }
399 void setThickMathSpace( double s ) { m_thickMathSpace.push( s ); }
400 void setVeryThickMathSpace( double s ) { m_veryThickMathSpace.push( s ); }
401 void setVeryVeryThickMathSpace( double s ) { m_veryVeryThickMathSpace.push( s ); }
402 void setDisplayStyle( bool ds ) { m_displayStyle.push( ds ); }
403 void setCustomDisplayStyle( bool cds ) { m_customDisplayStyle.push( cds ); }
404
405 void reset();
406 void resetSize();
407 void resetCharStyle();
408 void resetCharFamily();
409 void resetColor();
410 void resetBackground();
411 void resetFontFamily();
412 void resetFontWeight();
413 void resetFontStyle();
414
415 void resetScriptLevel();
416 void resetScriptSizeMultiplier();
417 void resetScriptMinSize();
418 void resetVeryVeryThinMathSpace();
419 void resetVeryThinMathSpace();
420 void resetThinMathSpace();
421 void resetMediumMathSpace();
422 void resetThickMathSpace();
423 void resetVeryThickMathSpace();
424 void resetVeryVeryThickMathSpace();
425 void resetDisplayStyle();
426
427 private:
428 // Size of the font in points (mathsize / fontsize)
429 TQValueStack<double> m_size;
430
431 // Whether a custom mathvariant attribute is in use
432 TQValueStack<bool> m_customMathVariant;
433
434 // Font style (mathvariant, fontweight, fontstyle)
435 TQValueStack<CharStyle> m_charStyle;
436
437 // Font family (mathvariant)
438 TQValueStack<CharFamily> m_charFamily;
439
440 // Foreground color (mathcolor, color)
441 TQValueStack<TQColor> m_color;
442
443 // Background color (mathbackground)
444 TQValueStack<TQColor> m_background;
445
446 // Font family (fontfamily)
447 TQValueStack<TQFont> m_font;
448
449 // Whether a custom fontfamily attribute is in use (instead of CharFamily)
450 TQValueStack<bool> m_customFontFamily;
451
452 // Font Weight (fontweight)
453 TQValueStack<bool> m_fontWeight;
454
455 // Whether a custom fontweight attribute is in use
456 TQValueStack<bool> m_customFontWeight;
457
458 // Font Style (fontstyle)
459 TQValueStack<bool> m_fontStyle;
460
461 // Whether a custom fontstyle attribute is in use
462 TQValueStack<bool> m_customFontStyle;
463
464 TQValueStack<int> m_scriptLevel;
465 TQValueStack<double> m_scriptSizeMultiplier;
466 TQValueStack<double> m_scriptMinSize;
467 TQValueStack<double> m_veryVeryThinMathSpace;
468 TQValueStack<double> m_veryThinMathSpace;
469 TQValueStack<double> m_thinMathSpace;
470 TQValueStack<double> m_mediumMathSpace;
471 TQValueStack<double> m_thickMathSpace;
472 TQValueStack<double> m_veryThickMathSpace;
473 TQValueStack<double> m_veryVeryThickMathSpace;
474 TQValueStack<bool> m_displayStyle;
475 TQValueStack<bool> m_customDisplayStyle;
476};
477
478KFORMULA_NAMESPACE_END
479
480#endif // CONTEXTSTYLE_H
TextStyle convertTextStyleIndex(TextStyle tstyle) const
Font-conversions a la TeX.
luPt getAdjustedSize(TextStyle tstyle, double factor) const
Calculates the font size corresponding to the given TextStyle.
TextStyle
Textstyles like in TeX.
IndexStyle convertIndexStyleLower(IndexStyle) const
Index-style-conversions a la TeX.
luPixel getLineWidth(double factor) const
All simple lines like the one that makes up a fraction.
void init(bool init=true)
ContextStyle()
Build a default context style.
IndexStyle convertIndexStyleUpper(IndexStyle istyle) const
Index-style-conversions a la TeX.
void setZoomAndResolution(int zoom, int dpiX, int dpiY)
Change the zoom factor to z (e.g.
void readConfig(TDEConfig *config, bool init=true)
luPixel getSpace(TextStyle tstyle, SpaceWidth space, double factor) const
TeX like spacings.
const SymbolTable & symbolTable() const
TextStyle convertTextStyleFraction(TextStyle tstyle) const
Font-conversions a la TeX.
Base class for all supported font styles.
Definition fontstyle.h:41
int zoom() const
The symbol table.
Definition symboltable.h:77