~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kformula/contextstyle.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <qfontmetrics.h>
22
22
#include <qstring.h>
23
23
 
 
24
#include <kdebug.h>
24
25
#include <koGlobal.h>
25
26
 
 
27
#include "cmstyle.h"
26
28
#include "contextstyle.h"
 
29
#include "esstixfontstyle.h"
 
30
#include "symbolfontstyle.h"
 
31
 
27
32
 
28
33
KFORMULA_NAMESPACE_BEGIN
29
34
 
30
35
 
31
 
void ContextStyle::TextStyleValues::setup( QFont font,
32
 
                                           double baseSize,
33
 
                                           double reduction )
34
 
{
35
 
    reductionFactor = reduction;
36
 
 
37
 
    font.setPointSizeFloat( baseSize );
38
 
    QFontMetrics fm( font );
39
 
 
40
 
    // Or better the real space required? ( boundingRect )
41
 
    quad = fm.width( 'M' );
42
 
}
43
 
 
44
 
 
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),
51
 
          emptyColor(Qt::blue)
 
37
    : symbolFont( "Symbol" ),
 
38
      defaultColor(Qt::black), numberColor(Qt::blue),
 
39
      operatorColor(Qt::darkGreen), errorColor(Qt::darkRed),
 
40
      emptyColor(Qt::blue), helpColor( Qt::gray ),
 
41
      m_sizeFactor( 0 )
52
42
{
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;
 
49
 
 
50
    textStyleValues[ displayStyle      ].setup( 1. );
 
51
    textStyleValues[ textStyle         ].setup( 1. );
 
52
    textStyleValues[ scriptStyle       ].setup( .7 );
 
53
    textStyleValues[ scriptScriptStyle ].setup( .49 );
54
54
 
55
55
    m_baseTextStyle = displayStyle;
56
56
 
57
57
    lineWidth = 1;
58
 
    emptyRectWidth = 10;
59
 
    emptyRectHeight = 10;
60
 
    //distance = 4;
61
 
    //operatorSpace = 4;
62
 
    baseSize = 18;
63
 
 
64
58
    linearMovement = false;
65
 
 
66
 
    centerSymbol = false;
67
 
    syntaxHighlighting = true;
68
 
 
 
59
    centerSymbol = true;
 
60
    m_syntaxHighlighting = true;
 
61
 
 
62
    m_fontStyle = 0;
 
63
}
 
64
 
 
65
 
 
66
ContextStyle::~ContextStyle()
 
67
{
 
68
    delete m_fontStyle;
 
69
}
 
70
 
 
71
 
 
72
void ContextStyle::init()
 
73
{
69
74
    setup();
70
 
}
71
 
 
 
75
    setFontStyle( m_fontStyleName );
 
76
}
 
77
 
 
78
 
 
79
void ContextStyle::setFontStyle( const QString& fontStyle )
 
80
{
 
81
    delete m_fontStyle;
 
82
    m_fontStyleName = fontStyle;
 
83
    if ( m_fontStyleName == "tex" ) {
 
84
        m_fontStyle = new CMStyle();
 
85
        if ( !m_fontStyle->init( this ) ) {
 
86
        }
 
87
    }
 
88
    else if ( m_fontStyleName == "esstix" ) {
 
89
        m_fontStyle = new EsstixFontStyle();
 
90
        if ( !m_fontStyle->init( this ) ) {
 
91
        }
 
92
    }
 
93
    else {
 
94
        // The SymbolFontStyle is always expected to work.
 
95
        m_fontStyle = new SymbolFontStyle();
 
96
        m_fontStyle->init( this );
 
97
    }
 
98
}
 
99
 
 
100
 
 
101
const SymbolTable& ContextStyle::symbolTable() const
 
102
{
 
103
    return *( m_fontStyle->symbolTable() );
 
104
}
 
105
 
 
106
 
 
107
void ContextStyle::readConfig( KConfig* config )
 
108
{
 
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();
 
120
 
 
121
    m_fontStyleName = config->readEntry( "fontStyle", "symbol" );
 
122
 
 
123
#if 0
 
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" );
 
148
    }
 
149
#endif
 
150
 
 
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 );
 
159
 
 
160
    m_syntaxHighlighting = config->readBoolEntry( "syntaxHighlighting", true );
 
161
}
 
162
 
 
163
void ContextStyle::setZoomAndResolution( int zoom, int dpiX, int dpiY )
 
164
{
 
165
    KoZoomHandler::setZoomAndResolution( zoom, dpiX, dpiY );
 
166
}
 
167
 
 
168
bool ContextStyle::setZoomAndResolution( int zoom, double zoomX, double zoomY, bool, bool )
 
169
{
 
170
    bool changes = m_zoom != zoom || m_zoomedResolutionX != zoomX || m_zoomedResolutionY != zoomY;
 
171
    m_zoom = zoom;
 
172
    m_zoomedResolutionX = zoomX;
 
173
    m_zoomedResolutionY = zoomY;
 
174
    return changes;
 
175
}
72
176
 
73
177
QColor ContextStyle::getNumberColor()   const
74
178
{
75
 
    if (syntaxHighlighting) {
 
179
    if ( edit() && syntaxHighlighting() ) {
76
180
        return numberColor;
77
181
    }
78
182
    return getDefaultColor();
80
184
 
81
185
QColor ContextStyle::getOperatorColor() const
82
186
{
83
 
    if (syntaxHighlighting) {
 
187
    if ( edit() && syntaxHighlighting() ) {
84
188
        return operatorColor;
85
189
    }
86
190
    return getDefaultColor();
88
192
 
89
193
QColor ContextStyle::getErrorColor()    const
90
194
{
91
 
    if (syntaxHighlighting) {
 
195
    if ( edit() && syntaxHighlighting() ) {
92
196
        return errorColor;
93
197
    }
94
198
    return getDefaultColor();
96
200
 
97
201
QColor ContextStyle::getEmptyColor()    const
98
202
{
99
 
    if (syntaxHighlighting) {
 
203
    if ( edit() && syntaxHighlighting() ) {
100
204
        return emptyColor;
101
205
    }
102
206
    return getDefaultColor();
103
207
}
104
208
 
105
 
 
106
 
 
107
 
void ContextStyle::setResolution(double zX, double zY)
108
 
{
109
 
    m_zoomedResolutionX = zX;
110
 
    m_zoomedResolutionY = zY;
111
 
}
 
209
QColor ContextStyle::getHelpColor()     const
 
210
{
 
211
    if ( edit() && syntaxHighlighting() ) {
 
212
        return helpColor;
 
213
    }
 
214
    return getDefaultColor();
 
215
}
 
216
 
 
217
void ContextStyle::setDefaultColor( const QColor& color )
 
218
{
 
219
    defaultColor = color;
 
220
}
 
221
void ContextStyle::setNumberColor( const QColor& color )
 
222
{
 
223
    numberColor = color;
 
224
}
 
225
void ContextStyle::setOperatorColor( const QColor& color )
 
226
{
 
227
    operatorColor = color;
 
228
}
 
229
void ContextStyle::setErrorColor( const QColor& color )
 
230
{
 
231
    errorColor = color;
 
232
}
 
233
void ContextStyle::setEmptyColor( const QColor& color )
 
234
{
 
235
    emptyColor = color;
 
236
}
 
237
void ContextStyle::setHelpColor( const QColor& color )
 
238
{
 
239
    helpColor = color;
 
240
}
 
241
 
 
242
#if 0
 
243
const QStringList& ContextStyle::requestedFonts() const
 
244
{
 
245
    return m_requestedFonts;
 
246
}
 
247
 
 
248
void ContextStyle::setRequestedFonts( const QStringList& list )
 
249
{
 
250
    m_requestedFonts = list;
 
251
    //table.init( this );
 
252
}
 
253
#endif
112
254
 
113
255
double ContextStyle::getReductionFactor( TextStyle tstyle ) const
114
256
{
115
257
    return textStyleValues[ tstyle ].reductionFactor;
116
258
}
117
259
 
118
 
double ContextStyle::getAdjustedSize( TextStyle tstyle ) const
119
 
{
120
 
    return zoomItY( baseSize*getReductionFactor( tstyle ) );
121
 
}
122
 
 
123
 
double ContextStyle::getThinSpace( TextStyle tstyle ) const
124
 
{
125
 
    return zoomItX( textStyleValues[ tstyle ].thinSpace() );
126
 
    //return textStyleValues[ tstyle ].thinSpace();
127
 
}
128
 
 
129
 
double ContextStyle::getMediumSpace( TextStyle tstyle ) const
130
 
{
131
 
    return zoomItX( textStyleValues[ tstyle ].mediumSpace() );
132
 
    //return textStyleValues[ tstyle ].mediumSpace();
133
 
}
134
 
 
135
 
double ContextStyle::getThickSpace( TextStyle tstyle ) const
136
 
{
137
 
    return zoomItX( textStyleValues[ tstyle ].thickSpace() );
138
 
    //return textStyleValues[ tstyle ].thickSpace();
139
 
}
140
 
 
141
 
 
142
 
double ContextStyle::getBaseSize() const
143
 
{
144
 
    return zoomItY( baseSize );
145
 
}
146
 
 
147
 
void ContextStyle::setUnzoomedBaseSize( double size )
148
 
{
149
 
    //double newSize = unzoomItY( size );
150
 
    double newSize = size;
151
 
    if ( newSize != baseSize ) {
152
 
        baseSize = newSize;
 
260
luPt ContextStyle::getAdjustedSize( TextStyle tstyle ) const
 
261
{
 
262
    return qRound( ptToLayoutUnitPt( m_sizeFactor*m_baseSize*getReductionFactor( tstyle ) ) );
 
263
}
 
264
 
 
265
luPixel ContextStyle::getSpace( TextStyle tstyle, SpaceWidth space ) const
 
266
{
 
267
    switch ( space ) {
 
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 );
 
273
    }
 
274
    return 0;
 
275
}
 
276
 
 
277
luPixel ContextStyle::getThinSpace( TextStyle tstyle ) const
 
278
{
 
279
    return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].thinSpace( quad ) );
 
280
}
 
281
 
 
282
luPixel ContextStyle::getMediumSpace( TextStyle tstyle ) const
 
283
{
 
284
    return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].mediumSpace( quad ) );
 
285
}
 
286
 
 
287
luPixel ContextStyle::getThickSpace( TextStyle tstyle ) const
 
288
{
 
289
    return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].thickSpace( quad ) );
 
290
}
 
291
 
 
292
luPixel ContextStyle::getQuadSpace( TextStyle tstyle ) const
 
293
{
 
294
    return ptToPixelX( m_sizeFactor*textStyleValues[ tstyle ].quadSpace( quad ) );
 
295
}
 
296
 
 
297
luPixel ContextStyle::axisHeight( TextStyle tstyle ) const
 
298
{
 
299
    //return ptToPixelY( textStyleValues[ tstyle ].axisHeight( m_axisHeight ) );
 
300
    return static_cast<luPixel>( m_sizeFactor*textStyleValues[ tstyle ].axisHeight( m_axisHeight ) );
 
301
}
 
302
 
 
303
luPt ContextStyle::getBaseSize() const
 
304
{
 
305
    return static_cast<luPt>( ptToLayoutUnitPt( m_sizeFactor*m_baseSize ) );
 
306
}
 
307
 
 
308
void ContextStyle::setBaseSize( int size )
 
309
{
 
310
    //kdDebug( 40000 ) << "ContextStyle::setBaseSize" << endl;
 
311
    if ( size != m_baseSize ) {
 
312
        m_baseSize = size;
153
313
        setup();
154
314
    }
155
315
}
156
316
 
157
 
 
158
 
double ContextStyle::getLineWidth() const
159
 
{
160
 
    return zoomItY( lineWidth );
161
 
}
162
 
 
163
 
double ContextStyle::getEmptyRectWidth() const
164
 
{
165
 
    return zoomItY( emptyRectWidth );
166
 
}
167
 
 
168
 
double ContextStyle::getEmptyRectHeight() const
169
 
{
170
 
    return zoomItY( emptyRectHeight );
 
317
void ContextStyle::setSizeFactor( double factor )
 
318
{
 
319
    m_sizeFactor = factor;
 
320
}
 
321
 
 
322
 
 
323
luPixel ContextStyle::getLineWidth() const
 
324
{
 
325
    return ptToLayoutUnitPixX( m_sizeFactor*lineWidth );
 
326
}
 
327
 
 
328
luPixel ContextStyle::getEmptyRectWidth() const
 
329
{
 
330
    return ptToLayoutUnitPixX( m_sizeFactor*m_baseSize/1.8 );
 
331
}
 
332
 
 
333
luPixel ContextStyle::getEmptyRectHeight() const
 
334
{
 
335
    return ptToLayoutUnitPixX( m_sizeFactor*m_baseSize/1.8 );
171
336
}
172
337
 
173
338
 
213
378
 
214
379
void ContextStyle::setup()
215
380
{
216
 
    //double size = getBaseSize();
217
 
    double size = baseSize;
218
 
    textStyleValues[ displayStyle      ].setup( getSymbolFont(), size, 1. );
219
 
    textStyleValues[ textStyle         ].setup( getSymbolFont(), size, 1. );
220
 
    textStyleValues[ scriptStyle       ].setup( getSymbolFont(), size, .7 );
221
 
    textStyleValues[ scriptScriptStyle ].setup( getSymbolFont(), size, .49 );
 
381
    luPt size = static_cast<luPt>( m_baseSize );
 
382
    QFont font = symbolFont;
 
383
    font.setPointSize( size );
 
384
    QFontMetrics fm( font );
 
385
 
 
386
    // Or better the real space required? ( boundingRect )
 
387
    quad = ptToLayoutUnitPt( fm.width( 'M' ) );
 
388
 
 
389
    font = QFont(defaultFont);
 
390
    font.setPointSize( size );
 
391
    QFontMetrics fm2( font );
 
392
    //m_axisHeight = ptToLayoutUnitPt( fm2.strikeOutPos() );
 
393
    //ptToLayoutUnitPixY
 
394
    //m_axisHeight = ptToLayoutUnitPt( pixelYToPt( fm2.strikeOutPos() ) );
 
395
    m_axisHeight = ptToLayoutUnitPixY( pixelYToPt( fm2.strikeOutPos() ) );
222
396
}
223
397
 
224
398
KFORMULA_NAMESPACE_END