22#include <tqfontmetrics.h>
28#include "contextstyle.h"
32KFORMULA_NAMESPACE_BEGIN
36 : symbolFont(
"Symbol" ),
37 defaultColor(TQt::black), numberColor(TQt::blue),
38 operatorColor(TQt::darkGreen), errorColor(TQt::darkRed),
39 emptyColor(TQt::blue), helpColor( TQt::gray ), m_sizeFactor( 0 )
48 textStyleValues[ displayStyle ].setup( 1. );
49 textStyleValues[ textStyle ].setup( 1. );
50 textStyleValues[ scriptStyle ].setup( .7 );
51 textStyleValues[ scriptScriptStyle ].setup( .49 );
53 m_baseTextStyle = displayStyle;
56 linearMovement =
false;
58 m_syntaxHighlighting =
true;
64ContextStyle::~ContextStyle()
73 setFontStyle( m_fontStyleName,
init );
77void ContextStyle::setFontStyle(
const TQString& fontStyle,
bool init )
80 m_fontStyleName = fontStyle;
88 return *( m_fontStyle->symbolTable() );
94 config->setGroup(
"kformula Font" );
95 TQString fontName = config->readEntry(
"defaultFont",
"Times,12,-1,5,50,1,0,0,0,0" );
96 defaultFont.fromString( fontName );
97 fontName = config->readEntry(
"nameFont",
"Times,12,-1,5,50,0,0,0,0,0" );
98 nameFont.fromString( fontName );
99 fontName = config->readEntry(
"numberFont",
"Times,12,-1,5,50,0,0,0,0,0" );
100 numberFont.fromString( fontName );
101 fontName = config->readEntry(
"operatorFont",
"Times,12,-1,5,50,0,0,0,0,0" );
102 operatorFont.fromString( fontName );
103 TQString baseSize = config->readEntry(
"baseSize",
"20" );
104 m_baseSize = baseSize.toInt();
106 if ( ! FontStyle::missingFonts(
init ).isEmpty() ) {
107 kdWarning( DEBUGID) <<
"Not all basic fonts found\n";
109 mathFont.fromString(
"Arev Sans");
110 bracketFont.fromString(
"cmex10");
114 config->setGroup(
"kformula Color" );
115 defaultColor = config->readColorEntry(
"defaultColor", &defaultColor );
116 numberColor = config->readColorEntry(
"numberColor", &numberColor );
117 operatorColor = config->readColorEntry(
"operatorColor", &operatorColor );
118 emptyColor = config->readColorEntry(
"emptyColor", &emptyColor );
119 errorColor = config->readColorEntry(
"errorColor", &errorColor );
120 helpColor = config->readColorEntry(
"helpColor", &helpColor );
122 m_syntaxHighlighting = config->readBoolEntry(
"syntaxHighlighting",
true );
132 bool changes = m_zoom !=
zoom || m_zoomedResolutionX != zoomX || m_zoomedResolutionY != zoomY;
134 m_zoomedResolutionX = zoomX;
135 m_zoomedResolutionY = zoomY;
139TQColor ContextStyle::getNumberColor()
const
141 if ( edit() && syntaxHighlighting() ) {
144 return getDefaultColor();
147TQColor ContextStyle::getOperatorColor()
const
149 if ( edit() && syntaxHighlighting() ) {
150 return operatorColor;
152 return getDefaultColor();
155TQColor ContextStyle::getErrorColor()
const
157 if ( edit() && syntaxHighlighting() ) {
160 return getDefaultColor();
163TQColor ContextStyle::getEmptyColor()
const
165 if ( edit() && syntaxHighlighting() ) {
168 return getDefaultColor();
171TQColor ContextStyle::getHelpColor()
const
173 if ( edit() && syntaxHighlighting() ) {
176 return getDefaultColor();
179void ContextStyle::setDefaultColor(
const TQColor& color )
181 defaultColor = color;
183void ContextStyle::setNumberColor(
const TQColor& color )
187void ContextStyle::setOperatorColor(
const TQColor& color )
189 operatorColor = color;
191void ContextStyle::setErrorColor(
const TQColor& color )
195void ContextStyle::setEmptyColor(
const TQColor& color )
199void ContextStyle::setHelpColor(
const TQColor& color )
205const TQStringList& ContextStyle::requestedFonts()
const
207 return m_requestedFonts;
210void ContextStyle::setRequestedFonts(
const TQStringList& list )
212 m_requestedFonts = list;
217double ContextStyle::getReductionFactor( TextStyle tstyle )
const
219 return textStyleValues[ tstyle ].reductionFactor;
226 * getReductionFactor( tstyle )
228 *
zoom() / 100.0 ) );
234 case NEGTHIN:
return -getThinSpace( tstyle, factor );
235 case THIN:
return getThinSpace( tstyle, factor );
236 case MEDIUM:
return getMediumSpace( tstyle, factor );
237 case THICK:
return getThickSpace( tstyle, factor );
238 case QUAD:
return getQuadSpace( tstyle, factor );
243luPixel ContextStyle::getThinSpace( TextStyle tstyle,
double factor )
const
246 * textStyleValues[ tstyle ].thinSpace( quad )
251luPixel ContextStyle::getMediumSpace( TextStyle tstyle,
double factor )
const
254 * textStyleValues[ tstyle ].mediumSpace( quad )
259luPixel ContextStyle::getThickSpace( TextStyle tstyle,
double factor )
const
262 * textStyleValues[ tstyle ].thickSpace( quad )
267luPixel ContextStyle::getQuadSpace( TextStyle tstyle,
double factor )
const
270 * textStyleValues[ tstyle ].quadSpace( quad )
275luPixel ContextStyle::axisHeight( TextStyle tstyle,
double factor )
const
278 return static_cast<luPixel
>( m_sizeFactor
279 * textStyleValues[ tstyle ].axisHeight( m_axisHeight )
284luPt ContextStyle::getBaseSize()
const
289void ContextStyle::setBaseSize(
int size )
292 if ( size != m_baseSize ) {
298void ContextStyle::setSizeFactor(
double factor )
300 m_sizeFactor = factor;
309luPixel ContextStyle::getEmptyRectWidth(
double factor )
const
314luPixel ContextStyle::getEmptyRectHeight(
double factor )
const
329 result = scriptStyle;
332 result = scriptScriptStyle;
346 result = scriptStyle;
349 result = scriptStyle;
352 result = scriptScriptStyle;
360void ContextStyle::setup()
362 luPt size =
static_cast<luPt
>( m_baseSize );
363 TQFont font = symbolFont;
364 font.setPointSize( size );
365 TQFontMetrics fm( font );
370 font = TQFont(defaultFont);
371 font.setPointSize( size );
372 TQFontMetrics fm2( font );
376 m_axisHeight = ptToLayoutUnitPixY( pixelYToPt( fm2.strikeOutPos() ) );
380double StyleAttributes::sizeFactor()
const
382 if ( m_size.empty() ) {
389bool StyleAttributes::customMathVariant()
const
391 if ( m_customMathVariant.empty() ) {
394 return m_customMathVariant.top();
397CharStyle StyleAttributes::charStyle()
const
399 if ( m_charStyle.empty() ) {
403 return m_charStyle.top();
406CharFamily StyleAttributes::charFamily()
const
408 if ( m_charFamily.empty() ) {
412 return m_charFamily.top();
415TQColor StyleAttributes::color()
const
417 if ( m_color.empty() ) {
419 return TQColor( TQt::black );
422 return m_color.top();
425TQColor StyleAttributes::background()
const
427 if ( m_background.empty() ) {
429 return TQColor( TQt::color0 );
431 return m_background.top();
434TQFont StyleAttributes::font()
const
436 if ( m_font.empty() ) {
442bool StyleAttributes::fontWeight()
const
444 if ( m_fontWeight.empty() ) {
447 return m_fontWeight.top();
450bool StyleAttributes::customFontWeight()
const
452 if ( m_customFontWeight.empty() ) {
455 return m_customFontWeight.top();
458bool StyleAttributes::fontStyle()
const
460 if ( m_fontStyle.empty() ) {
463 return m_fontStyle.top();
466bool StyleAttributes::customFontStyle()
const
468 if ( m_customFontStyle.empty() ) {
471 return m_customFontStyle.top();
474bool StyleAttributes::customFont()
const
476 if ( m_customFontFamily.empty() ) {
479 return m_customFontFamily.top();
482int StyleAttributes::scriptLevel()
const
484 if ( m_scriptLevel.empty() ) {
487 return m_scriptLevel.top();
490double StyleAttributes::scriptSizeMultiplier()
const
492 if ( m_scriptSizeMultiplier.empty() ) {
493 return scriptsizemultiplier;
495 return m_scriptSizeMultiplier.top();
498double StyleAttributes::scriptMinSize()
const
500 if ( m_scriptMinSize.empty() ) {
501 return scriptminsize;
503 return m_scriptMinSize.top();
506double StyleAttributes::veryVeryThinMathSpace()
const
508 if ( m_veryVeryThinMathSpace.empty() ) {
509 return veryverythinmathspace;
511 return m_veryVeryThinMathSpace.top();
514double StyleAttributes::veryThinMathSpace()
const
516 if ( m_veryThinMathSpace.empty() ) {
517 return verythinmathspace;
519 return m_veryThinMathSpace.top();
522double StyleAttributes::thinMathSpace()
const
524 if ( m_thinMathSpace.empty() ) {
525 return thinmathspace;
527 return m_thinMathSpace.top();
530double StyleAttributes::mediumMathSpace()
const
532 if ( m_mediumMathSpace.empty() ) {
533 return mediummathspace;
535 return m_mediumMathSpace.top();
538double StyleAttributes::thickMathSpace()
const
540 if ( m_thickMathSpace.empty() ) {
541 return thickmathspace;
543 return m_thickMathSpace.top();
546double StyleAttributes::veryThickMathSpace()
const
548 if ( m_veryThickMathSpace.empty() ) {
549 return verythickmathspace;
551 return m_veryThickMathSpace.top();
554double StyleAttributes::veryVeryThickMathSpace()
const
556 if ( m_veryVeryThickMathSpace.empty() ) {
557 return veryverythickmathspace;
559 return m_veryVeryThickMathSpace.top();
562bool StyleAttributes::displayStyle()
const
564 if ( m_displayStyle.empty() ) {
567 return m_displayStyle.top();
570bool StyleAttributes::customDisplayStyle()
const
572 if ( m_customDisplayStyle.empty() ) {
575 return m_customDisplayStyle.top();
578double StyleAttributes::getSpace( SizeType type,
double length )
const
581 case NegativeVeryVeryThinMathSpace:
582 return - veryVeryThinMathSpace();
583 case NegativeVeryThinMathSpace:
584 return - veryThinMathSpace();
585 case NegativeThinMathSpace:
586 return - thinMathSpace();
587 case NegativeMediumMathSpace:
588 return - mediumMathSpace();
589 case NegativeThickMathSpace:
590 return - thickMathSpace();
591 case NegativeVeryThickMathSpace:
592 return - veryThickMathSpace();
593 case NegativeVeryVeryThickMathSpace:
594 return - veryVeryThickMathSpace();
595 case VeryVeryThinMathSpace:
596 return veryVeryThinMathSpace();
597 case VeryThinMathSpace:
598 return veryThinMathSpace();
600 return thinMathSpace();
601 case MediumMathSpace:
602 return mediumMathSpace();
604 return thickMathSpace();
605 case VeryThickMathSpace:
606 return veryThickMathSpace();
607 case VeryVeryThickMathSpace:
608 return veryVeryThickMathSpace();
615void StyleAttributes::resetSize()
617 if ( ! m_size.empty() ) {
622void StyleAttributes::resetCharStyle()
624 if ( ! m_charStyle.empty() ) {
629void StyleAttributes::resetCharFamily()
631 if ( ! m_charFamily.empty() ) {
636void StyleAttributes::resetColor()
638 if ( ! m_color.empty() ) {
643void StyleAttributes::resetBackground()
645 if ( ! m_background.empty() ) {
650void StyleAttributes::resetFontFamily()
652 if ( ! m_customFontFamily.empty() ) {
653 if ( m_customFontFamily.pop() ) {
654 if ( ! m_font.empty() ) {
661void StyleAttributes::resetFontWeight()
663 if ( ! m_customFontWeight.empty() ) {
664 if ( m_customFontWeight.pop() ) {
665 if ( ! m_fontWeight.empty() ) {
672void StyleAttributes::resetFontStyle()
674 if ( ! m_customFontStyle.empty() ) {
675 if ( m_customFontStyle.pop() ) {
676 if ( ! m_fontStyle.empty() ) {
683void StyleAttributes::resetScriptLevel()
685 if ( ! m_scriptLevel.empty() ) {
690void StyleAttributes::resetScriptSizeMultiplier()
692 if ( ! m_scriptSizeMultiplier.empty() ) {
693 m_scriptSizeMultiplier.pop();
697void StyleAttributes::resetScriptMinSize()
699 if ( ! m_scriptMinSize.empty() ) {
700 m_scriptMinSize.pop();
704void StyleAttributes::resetVeryVeryThinMathSpace()
706 if ( ! m_veryVeryThinMathSpace.empty() ) {
707 m_veryVeryThinMathSpace.pop();
711void StyleAttributes::resetVeryThinMathSpace()
713 if ( ! m_veryThinMathSpace.empty() ) {
714 m_veryThinMathSpace.pop();
718void StyleAttributes::resetThinMathSpace()
720 if ( ! m_thinMathSpace.empty() ) {
721 m_thinMathSpace.pop();
725void StyleAttributes::resetMediumMathSpace()
727 if ( ! m_mediumMathSpace.empty() ) {
728 m_mediumMathSpace.pop();
732void StyleAttributes::resetThickMathSpace()
734 if ( ! m_thickMathSpace.empty() ) {
735 m_thickMathSpace.pop();
739void StyleAttributes::resetVeryThickMathSpace()
741 if ( ! m_veryThickMathSpace.empty() ) {
742 m_veryThickMathSpace.pop();
746void StyleAttributes::resetVeryVeryThickMathSpace()
748 if ( ! m_veryVeryThickMathSpace.empty() ) {
749 m_veryVeryThickMathSpace.pop();
753void StyleAttributes::resetDisplayStyle()
755 if ( ! m_customDisplayStyle.empty() ) {
756 if ( m_customDisplayStyle.pop() ) {
757 if ( ! m_displayStyle.empty() ) {
758 m_displayStyle.pop();
765KFORMULA_NAMESPACE_END
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.
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.
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.
bool init(ContextStyle *context, bool install=true)
lazy init support.
int ptToPixelX(double pt) const
Basic pt to pixel and pixel to pt conversions, valid at any zoom level, as well as at the Layout Unit...
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int ptToLayoutUnitPixX(double x_pt) const
The "document pt" -> "Layout Unit pixels" conversions, for convenience.
virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY)
Change the zoom factor to z (e.g.