21
21
#include <qfontmetrics.h>
22
22
#include <qstring.h>
24
25
#include <koGlobal.h>
26
28
#include "contextstyle.h"
29
#include "esstixfontstyle.h"
30
#include "symbolfontstyle.h"
28
33
KFORMULA_NAMESPACE_BEGIN
31
void ContextStyle::TextStyleValues::setup( QFont font,
35
reductionFactor = reduction;
37
font.setPointSizeFloat( baseSize );
38
QFontMetrics fm( font );
40
// Or better the real space required? ( boundingRect )
41
quad = fm.width( 'M' );
45
36
ContextStyle::ContextStyle()
46
: m_zoomedResolutionX(1.0), m_zoomedResolutionY(1.0),
47
defaultFont("times"), nameFont("times"), numberFont("times"),
48
operatorFont("times"), symbolFont("symbol",12,QFont::Normal,FALSE,QFont::AnyCharSet),
49
defaultColor(Qt::black), numberColor(Qt::blue),
50
operatorColor(Qt::darkGreen), errorColor(Qt::darkRed),
37
: symbolFont( "Symbol" ),
38
defaultColor(Qt::black), numberColor(Qt::blue),
39
operatorColor(Qt::darkGreen), errorColor(Qt::darkRed),
40
emptyColor(Qt::blue), helpColor( Qt::gray ),
53
defaultFont.setItalic(true);
43
// kdDebug() << "ContextStyle::ContextStyle" << endl
44
// << "defaultFont: " << defaultFont.rawName() << endl
45
// << "nameFont: " << nameFont.rawName() << endl
46
// << "numberFont: " << numberFont.rawName() << endl
47
// << "operatorFont: " << operatorFont.rawName() << endl
48
// << "symbolFont: " << symbolFont.rawName() << endl;
50
textStyleValues[ displayStyle ].setup( 1. );
51
textStyleValues[ textStyle ].setup( 1. );
52
textStyleValues[ scriptStyle ].setup( .7 );
53
textStyleValues[ scriptScriptStyle ].setup( .49 );
55
55
m_baseTextStyle = displayStyle;
64
58
linearMovement = false;
67
syntaxHighlighting = true;
60
m_syntaxHighlighting = true;
66
ContextStyle::~ContextStyle()
72
void ContextStyle::init()
75
setFontStyle( m_fontStyleName );
79
void ContextStyle::setFontStyle( const QString& fontStyle )
82
m_fontStyleName = fontStyle;
83
if ( m_fontStyleName == "tex" ) {
84
m_fontStyle = new CMStyle();
85
if ( !m_fontStyle->init( this ) ) {
88
else if ( m_fontStyleName == "esstix" ) {
89
m_fontStyle = new EsstixFontStyle();
90
if ( !m_fontStyle->init( this ) ) {
94
// The SymbolFontStyle is always expected to work.
95
m_fontStyle = new SymbolFontStyle();
96
m_fontStyle->init( this );
101
const SymbolTable& ContextStyle::symbolTable() const
103
return *( m_fontStyle->symbolTable() );
107
void ContextStyle::readConfig( KConfig* config )
109
config->setGroup( "kformula Font" );
110
QString fontName = config->readEntry( "defaultFont", "Times,12,-1,5,50,1,0,0,0,0" );
111
defaultFont.fromString( fontName );
112
fontName = config->readEntry( "nameFont", "Times,12,-1,5,50,0,0,0,0,0" );
113
nameFont.fromString( fontName );
114
fontName = config->readEntry( "numberFont", "Times,12,-1,5,50,0,0,0,0,0" );
115
numberFont.fromString( fontName );
116
fontName = config->readEntry( "operatorFont", "Times,12,-1,5,50,0,0,0,0,0" );
117
operatorFont.fromString( fontName );
118
QString baseSize = config->readEntry( "baseSize", "20" );
119
m_baseSize = baseSize.toInt();
121
m_fontStyleName = config->readEntry( "fontStyle", "symbol" );
124
m_requestedFonts = config->readListEntry( "usedMathFonts" );
125
if ( m_requestedFonts.size() == 0 ) {
126
m_requestedFonts.push_back( "esstixone" );
127
m_requestedFonts.push_back( "esstixtwo" );
128
m_requestedFonts.push_back( "esstixthree" );
129
m_requestedFonts.push_back( "esstixfour" );
130
m_requestedFonts.push_back( "esstixfive" );
131
m_requestedFonts.push_back( "esstixsix" );
132
m_requestedFonts.push_back( "esstixseven" );
133
m_requestedFonts.push_back( "esstixeight" );
134
m_requestedFonts.push_back( "esstixnine" );
135
m_requestedFonts.push_back( "esstixten" );
136
m_requestedFonts.push_back( "esstixeleven" );
137
m_requestedFonts.push_back( "esstixtwelve" );
138
m_requestedFonts.push_back( "esstixthirteen" );
139
m_requestedFonts.push_back( "esstixfourteen" );
140
m_requestedFonts.push_back( "esstixfifteen" );
141
m_requestedFonts.push_back( "esstixsixteen" );
142
m_requestedFonts.push_back( "esstixseventeen" );
143
// m_requestedFonts.push_back( "mt extra" );
144
// m_requestedFonts.push_back( "mt symbol" );
145
// m_requestedFonts.push_back( "euclid math one" );
146
// m_requestedFonts.push_back( "euclid math two" );
147
// m_requestedFonts.push_back( "euclid symbol" );
151
// There's no gui right anymore but I'll leave it here...
152
config->setGroup( "kformula Color" );
153
defaultColor = config->readColorEntry( "defaultColor", &defaultColor );
154
numberColor = config->readColorEntry( "numberColor", &numberColor );
155
operatorColor = config->readColorEntry( "operatorColor", &operatorColor );
156
emptyColor = config->readColorEntry( "emptyColor", &emptyColor );
157
errorColor = config->readColorEntry( "errorColor", &errorColor );
158
helpColor = config->readColorEntry( "helpColor", &helpColor );
160
m_syntaxHighlighting = config->readBoolEntry( "syntaxHighlighting", true );
163
void ContextStyle::setZoomAndResolution( int zoom, int dpiX, int dpiY )
165
KoZoomHandler::setZoomAndResolution( zoom, dpiX, dpiY );
168
bool ContextStyle::setZoomAndResolution( int zoom, double zoomX, double zoomY, bool, bool )
170
bool changes = m_zoom != zoom || m_zoomedResolutionX != zoomX || m_zoomedResolutionY != zoomY;
172
m_zoomedResolutionX = zoomX;
173
m_zoomedResolutionY = zoomY;
73
177
QColor ContextStyle::getNumberColor() const
75
if (syntaxHighlighting) {
179
if ( edit() && syntaxHighlighting() ) {
76
180
return numberColor;
78
182
return getDefaultColor();
97
201
QColor ContextStyle::getEmptyColor() const
99
if (syntaxHighlighting) {
203
if ( edit() && syntaxHighlighting() ) {
100
204
return emptyColor;
102
206
return getDefaultColor();
107
void ContextStyle::setResolution(double zX, double zY)
109
m_zoomedResolutionX = zX;
110
m_zoomedResolutionY = zY;
209
QColor ContextStyle::getHelpColor() const
211
if ( edit() && syntaxHighlighting() ) {
214
return getDefaultColor();
217
void ContextStyle::setDefaultColor( const QColor& color )
219
defaultColor = color;
221
void ContextStyle::setNumberColor( const QColor& color )
225
void ContextStyle::setOperatorColor( const QColor& color )
227
operatorColor = color;
229
void ContextStyle::setErrorColor( const QColor& color )
233
void ContextStyle::setEmptyColor( const QColor& color )
237
void ContextStyle::setHelpColor( const QColor& color )
243
const QStringList& ContextStyle::requestedFonts() const
245
return m_requestedFonts;
248
void ContextStyle::setRequestedFonts( const QStringList& list )
250
m_requestedFonts = list;
251
//table.init( this );
113
255
double ContextStyle::getReductionFactor( TextStyle tstyle ) const
115
257
return textStyleValues[ tstyle ].reductionFactor;
118
double ContextStyle::getAdjustedSize( TextStyle tstyle ) const
120
return zoomItY( baseSize*getReductionFactor( tstyle ) );
123
double ContextStyle::getThinSpace( TextStyle tstyle ) const
125
return zoomItX( textStyleValues[ tstyle ].thinSpace() );
126
//return textStyleValues[ tstyle ].thinSpace();
129
double ContextStyle::getMediumSpace( TextStyle tstyle ) const
131
return zoomItX( textStyleValues[ tstyle ].mediumSpace() );
132
//return textStyleValues[ tstyle ].mediumSpace();
135
double ContextStyle::getThickSpace( TextStyle tstyle ) const
137
return zoomItX( textStyleValues[ tstyle ].thickSpace() );
138
//return textStyleValues[ tstyle ].thickSpace();
142
double ContextStyle::getBaseSize() const
144
return zoomItY( baseSize );
147
void ContextStyle::setUnzoomedBaseSize( double size )
149
//double newSize = unzoomItY( size );
150
double newSize = size;
151
if ( newSize != baseSize ) {
260
luPt ContextStyle::getAdjustedSize( TextStyle tstyle ) const
262
return qRound( ptToLayoutUnitPt( m_sizeFactor*m_baseSize*getReductionFactor( tstyle ) ) );
265
luPixel ContextStyle::getSpace( TextStyle tstyle, SpaceWidth space ) const
268
case NEGTHIN: return -getThinSpace( tstyle );
269
case THIN: return getThinSpace( tstyle );
270
case MEDIUM: return getMediumSpace( tstyle );
271
case THICK: return getThickSpace( tstyle );
272
case QUAD: return getQuadSpace( tstyle );
277
luPixel ContextStyle::getThinSpace( TextStyle tstyle ) const
279
return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].thinSpace( quad ) );
282
luPixel ContextStyle::getMediumSpace( TextStyle tstyle ) const
284
return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].mediumSpace( quad ) );
287
luPixel ContextStyle::getThickSpace( TextStyle tstyle ) const
289
return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].thickSpace( quad ) );
292
luPixel ContextStyle::getQuadSpace( TextStyle tstyle ) const
294
return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].quadSpace( quad ) );
297
luPixel ContextStyle::axisHeight( TextStyle tstyle ) const
299
//return ptToPixelY( textStyleValues[ tstyle ].axisHeight( m_axisHeight ) );
300
return static_cast<luPixel>( m_sizeFactor*textStyleValues[ tstyle ].axisHeight( m_axisHeight ) );
303
luPt ContextStyle::getBaseSize() const
305
return static_cast<luPt>( ptToLayoutUnitPt( m_sizeFactor*m_baseSize ) );
308
void ContextStyle::setBaseSize( int size )
310
//kdDebug( 40000 ) << "ContextStyle::setBaseSize" << endl;
311
if ( size != m_baseSize ) {
158
double ContextStyle::getLineWidth() const
160
return zoomItY( lineWidth );
163
double ContextStyle::getEmptyRectWidth() const
165
return zoomItY( emptyRectWidth );
168
double ContextStyle::getEmptyRectHeight() const
170
return zoomItY( emptyRectHeight );
317
void ContextStyle::setSizeFactor( double factor )
319
m_sizeFactor = factor;
323
luPixel ContextStyle::getLineWidth() const
325
return ptToLayoutUnitPixX( m_sizeFactor*lineWidth );
328
luPixel ContextStyle::getEmptyRectWidth() const
330
return ptToLayoutUnitPixX( m_sizeFactor*m_baseSize/1.8 );
333
luPixel ContextStyle::getEmptyRectHeight() const
335
return ptToLayoutUnitPixX( m_sizeFactor*m_baseSize/1.8 );