You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
892 lines
29 KiB
892 lines
29 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2003 Ulrich Kuettler <ulrich.kuettler@gmx.de>
|
||
|
Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqpen.h>
|
||
|
#include <tqfontdatabase.h>
|
||
|
#include <tqapplication.h>
|
||
15 years ago
|
|
||
|
#include <kstaticdeleter.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdeio/netaccess.h>
|
||
|
#include <tdeio/job.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
#include "fontstyle.h"
|
||
|
|
||
|
|
||
|
KFORMULA_NAMESPACE_BEGIN
|
||
|
|
||
4 years ago
|
#include "unicodetable.cpp"
|
||
15 years ago
|
|
||
|
bool FontStyle::m_installed = false;
|
||
|
|
||
|
bool FontStyle::init( ContextStyle* style, bool install )
|
||
|
{
|
||
|
if (!m_installed && install)
|
||
|
installFonts();
|
||
|
m_symbolTable.init( style->getMathFont() );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
// Cache the family list from TQFontDatabase after fixing it up (no foundry, lowercase)
|
||
15 years ago
|
class FontList {
|
||
|
public:
|
||
|
FontList() {
|
||
14 years ago
|
TQFontDatabase db;
|
||
13 years ago
|
const TQStringList lst = db.families();
|
||
14 years ago
|
for ( TQStringList::const_iterator it = lst.begin(), end = lst.end() ; it != end ; ++it ) {
|
||
|
const TQString name = *it;
|
||
14 years ago
|
int i = name.find('[');
|
||
14 years ago
|
TQString family = name;
|
||
15 years ago
|
// Remove foundry
|
||
|
if ( i > -1 ) {
|
||
14 years ago
|
const int li = name.findRev(']');
|
||
15 years ago
|
if (i < li) {
|
||
|
if (name[i - 1] == ' ')
|
||
|
i--;
|
||
|
family = name.left(i);
|
||
|
}
|
||
|
}
|
||
|
m_fontNames.append( family.lower() );
|
||
|
}
|
||
|
}
|
||
14 years ago
|
bool hasFont( const TQString& fontName ) const {
|
||
14 years ago
|
return m_fontNames.find( fontName ) != m_fontNames.end();
|
||
15 years ago
|
}
|
||
14 years ago
|
TQStringList m_fontNames;
|
||
15 years ago
|
};
|
||
|
static FontList* s_fontList = 0;
|
||
|
static KStaticDeleter<FontList> s_fontList_sd;
|
||
|
|
||
14 years ago
|
void FontStyle::testFont( TQStringList& missing, const TQString& fontName ) {
|
||
15 years ago
|
if ( !s_fontList )
|
||
|
s_fontList_sd.setObject( s_fontList, new FontList() );
|
||
|
if ( !s_fontList->hasFont( fontName ) ) {
|
||
|
kdWarning(39001) << "Font '" << fontName << "' not found" << endl;
|
||
|
missing.append( fontName );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQStringList FontStyle::missingFonts( bool install )
|
||
15 years ago
|
{
|
||
|
if (!m_installed && install)
|
||
|
installFonts();
|
||
|
|
||
14 years ago
|
TQStringList missing = missingFontsInternal();
|
||
15 years ago
|
return missing;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQStringList FontStyle::missingFontsInternal()
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList missing;
|
||
15 years ago
|
|
||
|
testFont( missing, "cmex10" );
|
||
|
testFont( missing, "arev sans");
|
||
|
|
||
|
return missing;
|
||
|
}
|
||
|
|
||
|
void FontStyle::installFonts()
|
||
|
{
|
||
|
if (m_installed)
|
||
|
return;
|
||
14 years ago
|
TQStringList missing = missingFontsInternal();
|
||
15 years ago
|
if (!missing.isEmpty())
|
||
|
{
|
||
14 years ago
|
TQStringList urlList;
|
||
|
for (TQStringList::iterator it = missing.begin(); it != missing.end(); ++it)
|
||
15 years ago
|
{
|
||
|
if ( *it == "arev sans" ) {
|
||
12 years ago
|
if (!TDEIO::NetAccess::exists("fonts:/Personal/Arev.ttf", true, NULL))
|
||
15 years ago
|
urlList.append(locate("data", "kformula/fonts/Arev.ttf"));
|
||
12 years ago
|
if (!TDEIO::NetAccess::exists("fonts:/Personal/ArevIt.ttf", true, NULL))
|
||
15 years ago
|
urlList.append(locate("data", "kformula/fonts/ArevIt.ttf"));
|
||
12 years ago
|
if (!TDEIO::NetAccess::exists("fonts:/Personal/ArevBd.ttf", true, NULL))
|
||
15 years ago
|
urlList.append(locate("data", "kformula/fonts/ArevBd.ttf"));
|
||
12 years ago
|
if (!TDEIO::NetAccess::exists("fonts:/Personal/ArevBI.ttf", true, NULL))
|
||
15 years ago
|
urlList.append(locate("data", "kformula/fonts/ArevBI.ttf"));
|
||
|
}
|
||
|
else {
|
||
12 years ago
|
if (!TDEIO::NetAccess::exists("fonts:/Personal/" + *it + ".ttf", true, NULL))
|
||
15 years ago
|
urlList.append(locate("data", "kformula/fonts/" + *it + ".ttf"));
|
||
|
}
|
||
|
}
|
||
12 years ago
|
TDEIO::copy(urlList, "fonts:/Personal/", false);
|
||
14 years ago
|
KMessageBox::information(tqApp->mainWidget(),
|
||
15 years ago
|
i18n("Some fonts have been installed to assure that symbols in formulas are properly visualized. You must restart the application in order so that changes take effect"));
|
||
|
}
|
||
|
m_installed = true;
|
||
|
}
|
||
|
|
||
|
Artwork* FontStyle::createArtwork( SymbolType type ) const
|
||
|
{
|
||
|
return new Artwork( type );
|
||
|
}
|
||
|
|
||
|
// We claim that all chars come from the same font.
|
||
|
// It's up to the font tables to ensure this.
|
||
14 years ago
|
const TQChar leftRoundBracket[] = {
|
||
15 years ago
|
0x30, // uppercorner
|
||
|
0x40, // lowercorner
|
||
|
0x42 // line
|
||
|
};
|
||
14 years ago
|
const TQChar leftSquareBracket[] = {
|
||
15 years ago
|
0x32, // uppercorner
|
||
|
0x34, // lowercorner
|
||
|
0x36 // line
|
||
|
};
|
||
14 years ago
|
const TQChar leftCurlyBracket[] = {
|
||
15 years ago
|
0x38, // uppercorner
|
||
|
0x3A, // lowercorner
|
||
|
0x3E, // line
|
||
|
0x3C // middle
|
||
|
};
|
||
|
|
||
14 years ago
|
const TQChar leftLineBracket[] = {
|
||
15 years ago
|
0x36, // line
|
||
|
0x36, // line
|
||
|
0x36 // line
|
||
|
};
|
||
14 years ago
|
const TQChar rightLineBracket[] = {
|
||
15 years ago
|
0x37, // line
|
||
|
0x37, // line
|
||
|
0x37 // line
|
||
|
};
|
||
|
|
||
14 years ago
|
const TQChar rightRoundBracket[] = {
|
||
15 years ago
|
0x31, // uppercorner
|
||
|
0x41, // lowercorner
|
||
|
0x43 // line
|
||
|
};
|
||
14 years ago
|
const TQChar rightSquareBracket[] = {
|
||
15 years ago
|
0x33, // uppercorner
|
||
|
0x35, // lowercorner
|
||
|
0x37 // line
|
||
|
};
|
||
14 years ago
|
const TQChar rightCurlyBracket[] = {
|
||
15 years ago
|
0x39, // uppercorner
|
||
|
0x3B, // lowercorner
|
||
|
0x3E, // line
|
||
|
0x3D // middle
|
||
|
};
|
||
|
|
||
|
|
||
|
static const char cmex_LeftSquareBracket = 163;
|
||
|
static const char cmex_RightSquareBracket = 164;
|
||
|
static const char cmex_LeftCurlyBracket = 169;
|
||
|
static const char cmex_RightCurlyBracket = 170;
|
||
|
static const char cmex_LeftCornerBracket = 173;
|
||
|
static const char cmex_RightCornerBracket = 174;
|
||
|
static const char cmex_LeftRoundBracket = 161;
|
||
|
static const char cmex_RightRoundBracket = 162;
|
||
|
static const char cmex_SlashBracket = 177;
|
||
|
static const char cmex_BackSlashBracket = 178;
|
||
|
//static const char cmex_LeftLineBracket = 0x4b;
|
||
|
//static const char cmex_RightLineBracket = 0x4b;
|
||
|
|
||
|
// use the big symbols here
|
||
|
static const char cmex_Int = 90;
|
||
|
static const char cmex_Sum = 88;
|
||
|
static const char cmex_Prod = 89;
|
||
|
|
||
|
|
||
|
// cmex is a special font with symbols in four sizes.
|
||
|
static short cmex_nextchar( short ch )
|
||
|
{
|
||
|
switch ( ch ) {
|
||
|
case 161: return 179;
|
||
|
case 162: return 180;
|
||
|
case 163: return 104;
|
||
|
case 164: return 105;
|
||
|
case 169: return 110;
|
||
|
case 170: return 111;
|
||
|
case 165: return 106;
|
||
|
case 166: return 107;
|
||
|
case 167: return 108;
|
||
|
case 168: return 109;
|
||
|
case 173: return 68;
|
||
|
case 174: return 69;
|
||
|
case 177: return 46;
|
||
|
case 178: return 47;
|
||
|
|
||
|
case 179: return 181;
|
||
|
case 180: return 182;
|
||
|
case 104: return 183;
|
||
|
case 105: return 184;
|
||
|
case 110: return 189;
|
||
|
case 111: return 190;
|
||
|
case 106: return 185;
|
||
|
case 107: return 186;
|
||
|
case 108: return 187;
|
||
|
case 109: return 188;
|
||
|
case 68: return 191;
|
||
|
case 69: return 192;
|
||
|
case 46: return 193;
|
||
|
case 47: return 194;
|
||
|
|
||
|
case 181: return 195;
|
||
|
case 182: return 33;
|
||
|
case 183: return 34;
|
||
|
case 184: return 35;
|
||
|
case 189: return 40;
|
||
|
case 190: return 41;
|
||
|
case 185: return 36;
|
||
|
case 186: return 37;
|
||
|
case 187: return 38;
|
||
|
case 188: return 39;
|
||
|
case 191: return 42;
|
||
|
case 192: return 43;
|
||
|
case 193: return 44;
|
||
|
case 194: return 45;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
bool Artwork::calcCMDelimiterSize( const ContextStyle& context,
|
||
|
uchar c,
|
||
|
luPt fontSize,
|
||
14 years ago
|
luPt parentSize )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQFont f( "cmex10" );
|
||
14 years ago
|
f.setPointSizeFloat( context.layoutUnitPtToPt( fontSize ) );
|
||
14 years ago
|
TQFontMetrics fm( f );
|
||
15 years ago
|
|
||
|
for ( char i=1; c != 0; ++i ) {
|
||
|
LuPixelRect bound = fm.boundingRect( c );
|
||
|
|
||
|
luPt height = context.ptToLayoutUnitPt( bound.height() );
|
||
14 years ago
|
if ( height >= parentSize ) {
|
||
15 years ago
|
luPt width = context.ptToLayoutUnitPt( fm.width( c ) );
|
||
|
luPt baseline = context.ptToLayoutUnitPt( -bound.top() );
|
||
|
|
||
|
cmChar = c;
|
||
|
|
||
|
setHeight( height );
|
||
|
setWidth( width );
|
||
|
setBaseline( baseline );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
c = cmex_nextchar( c );
|
||
|
}
|
||
|
|
||
|
// Build it up from pieces.
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Artwork::calcLargest( const ContextStyle& context,
|
||
|
uchar c, luPt fontSize )
|
||
|
{
|
||
14 years ago
|
TQFont f( "cmex10" );
|
||
14 years ago
|
f.setPointSizeFloat( context.layoutUnitPtToPt( fontSize ) );
|
||
14 years ago
|
TQFontMetrics fm( f );
|
||
15 years ago
|
|
||
|
cmChar = c;
|
||
|
for ( ;; ) {
|
||
|
c = cmex_nextchar( c );
|
||
|
if ( c == 0 ) {
|
||
|
break;
|
||
|
}
|
||
|
cmChar = c;
|
||
|
}
|
||
|
|
||
|
LuPixelRect bound = fm.boundingRect( cmChar );
|
||
|
|
||
|
luPt height = context.ptToLayoutUnitPt( bound.height() );
|
||
|
luPt width = context.ptToLayoutUnitPt( fm.width( cmChar ) );
|
||
|
luPt baseline = context.ptToLayoutUnitPt( -bound.top() );
|
||
|
|
||
|
setHeight( height );
|
||
|
setWidth( width );
|
||
|
setBaseline( baseline );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::drawCMDelimiter( TQPainter& painter, const ContextStyle& style,
|
||
15 years ago
|
luPixel x, luPixel y,
|
||
|
luPt height )
|
||
|
{
|
||
14 years ago
|
TQFont f( "cmex10" );
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitToFontSize( height, false ) );
|
||
15 years ago
|
|
||
|
painter.setFont( f );
|
||
14 years ago
|
painter.drawText( style.layoutUnitToPixelX( x ),
|
||
|
style.layoutUnitToPixelY( y + getBaseline() ),
|
||
14 years ago
|
TQString( TQChar( cmChar ) ) );
|
||
15 years ago
|
|
||
|
// Debug
|
||
|
#if 0
|
||
14 years ago
|
TQFontMetrics fm( f );
|
||
15 years ago
|
LuPixelRect bound = fm.boundingRect( cmChar );
|
||
14 years ago
|
painter.setBrush(TQt::NoBrush);
|
||
|
painter.setPen(TQt::green);
|
||
14 years ago
|
painter.drawRect( style.layoutUnitToPixelX( x ),
|
||
|
style.layoutUnitToPixelY( y ),
|
||
15 years ago
|
fm.width( cmChar ),
|
||
|
bound.height() );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
|
Artwork::Artwork(SymbolType t)
|
||
|
: baseline( -1 ), type(t)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void Artwork::calcSizes( const ContextStyle& style,
|
||
|
ContextStyle::TextStyle tstyle,
|
||
|
double factor,
|
||
14 years ago
|
luPt parentSize )
|
||
15 years ago
|
{
|
||
|
setBaseline( -1 );
|
||
|
cmChar = -1;
|
||
|
luPt mySize = style.getAdjustedSize( tstyle, factor );
|
||
|
switch (getType()) {
|
||
|
case LeftSquareBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_LeftSquareBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcRoundBracket( style, leftSquareBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case RightSquareBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_RightSquareBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcRoundBracket( style, rightSquareBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case LeftLineBracket:
|
||
14 years ago
|
calcRoundBracket( style, leftLineBracket, parentSize, mySize );
|
||
15 years ago
|
setWidth( getWidth()/2 );
|
||
|
break;
|
||
|
case RightLineBracket:
|
||
14 years ago
|
calcRoundBracket( style, rightLineBracket, parentSize, mySize );
|
||
15 years ago
|
setWidth( getWidth()/2 );
|
||
|
break;
|
||
|
case SlashBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_SlashBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
calcLargest( style, cmex_SlashBracket, mySize );
|
||
|
break;
|
||
|
case BackSlashBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_BackSlashBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
calcLargest( style, cmex_BackSlashBracket, mySize );
|
||
|
break;
|
||
|
case LeftCornerBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_LeftCornerBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
calcLargest( style, cmex_LeftCornerBracket, mySize );
|
||
|
break;
|
||
|
case RightCornerBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_RightCornerBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
calcLargest( style, cmex_RightCornerBracket, mySize );
|
||
|
break;
|
||
|
case LeftRoundBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_LeftRoundBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcRoundBracket( style, leftRoundBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case RightRoundBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_RightRoundBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcRoundBracket( style, rightRoundBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case EmptyBracket:
|
||
14 years ago
|
setHeight(parentSize);
|
||
15 years ago
|
//setWidth(style.getEmptyRectWidth());
|
||
|
setWidth(0);
|
||
|
break;
|
||
|
case LeftCurlyBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_LeftCurlyBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcCurlyBracket( style, leftCurlyBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case RightCurlyBracket:
|
||
|
if ( calcCMDelimiterSize( style, cmex_RightCurlyBracket,
|
||
14 years ago
|
mySize, parentSize ) ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
calcCurlyBracket( style, rightCurlyBracket, parentSize, mySize );
|
||
15 years ago
|
break;
|
||
|
case Integral:
|
||
|
calcCharSize( style, style.getBracketFont(), mySize, cmex_Int );
|
||
|
break;
|
||
|
case Sum:
|
||
|
calcCharSize( style, style.getBracketFont(), mySize, cmex_Sum );
|
||
|
break;
|
||
|
case Product:
|
||
|
calcCharSize( style, style.getBracketFont(), mySize, cmex_Prod );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Artwork::calcSizes( const ContextStyle& style,
|
||
|
ContextStyle::TextStyle tstyle,
|
||
|
double factor )
|
||
|
{
|
||
|
luPt mySize = style.getAdjustedSize( tstyle, factor );
|
||
|
switch (type) {
|
||
|
case LeftSquareBracket:
|
||
|
calcCharSize(style, mySize, leftSquareBracketChar);
|
||
|
break;
|
||
|
case RightSquareBracket:
|
||
|
calcCharSize(style, mySize, rightSquareBracketChar);
|
||
|
break;
|
||
|
case LeftLineBracket:
|
||
|
case RightLineBracket:
|
||
|
calcCharSize(style, mySize, verticalLineChar);
|
||
|
break;
|
||
|
case SlashBracket:
|
||
|
calcCharSize(style, mySize, slashChar);
|
||
|
break;
|
||
|
case BackSlashBracket:
|
||
|
calcCharSize(style, mySize, backSlashChar);
|
||
|
break;
|
||
|
case LeftCornerBracket:
|
||
|
calcCharSize(style, mySize, leftAngleBracketChar);
|
||
|
break;
|
||
|
case RightCornerBracket:
|
||
|
calcCharSize(style, mySize, rightAngleBracketChar);
|
||
|
break;
|
||
|
case LeftRoundBracket:
|
||
|
calcCharSize(style, mySize, leftParenthesisChar);
|
||
|
break;
|
||
|
case RightRoundBracket:
|
||
|
calcCharSize(style, mySize, rightParenthesisChar);
|
||
|
break;
|
||
|
case EmptyBracket:
|
||
|
//calcCharSize(style, mySize, spaceChar);
|
||
|
setHeight(0);
|
||
|
//setWidth(style.getEmptyRectWidth());
|
||
|
setWidth(0);
|
||
|
break;
|
||
|
case LeftCurlyBracket:
|
||
|
calcCharSize(style, mySize, leftCurlyBracketChar);
|
||
|
break;
|
||
|
case RightCurlyBracket:
|
||
|
calcCharSize(style, mySize, rightCurlyBracketChar);
|
||
|
break;
|
||
|
case Integral:
|
||
|
case Sum:
|
||
|
case Product:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::draw(TQPainter& painter, const LuPixelRect& /*r*/,
|
||
15 years ago
|
const ContextStyle& context, ContextStyle::TextStyle tstyle,
|
||
14 years ago
|
StyleAttributes& style, const LuPixelPoint& parentOrigin)
|
||
15 years ago
|
{
|
||
|
luPt mySize = context.getAdjustedSize( tstyle, style.sizeFactor() );
|
||
14 years ago
|
luPixel myX = parentOrigin.x() + getX();
|
||
|
luPixel myY = parentOrigin.y() + getY();
|
||
15 years ago
|
/*
|
||
|
if ( !LuPixelRect( myX, myY, getWidth(), getHeight() ).intersects( r ) )
|
||
|
return;
|
||
|
*/
|
||
|
|
||
|
painter.setPen(context.getDefaultColor());
|
||
|
|
||
|
switch (type) {
|
||
|
case LeftSquareBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, leftSquareBracketChar);
|
||
|
break;
|
||
|
case RightSquareBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, rightSquareBracketChar);
|
||
|
break;
|
||
|
case LeftCurlyBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, leftCurlyBracketChar);
|
||
|
break;
|
||
|
case RightCurlyBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, rightCurlyBracketChar);
|
||
|
break;
|
||
|
case LeftLineBracket:
|
||
|
case RightLineBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, verticalLineChar);
|
||
|
break;
|
||
|
case SlashBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, slashChar);
|
||
|
break;
|
||
|
case BackSlashBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, backSlashChar);
|
||
|
break;
|
||
|
case LeftCornerBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, leftAngleBracketChar);
|
||
|
break;
|
||
|
case RightCornerBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, rightAngleBracketChar);
|
||
|
break;
|
||
|
case LeftRoundBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, leftParenthesisChar);
|
||
|
break;
|
||
|
case RightRoundBracket:
|
||
|
drawCharacter(painter, context, myX, myY, mySize, rightParenthesisChar);
|
||
|
break;
|
||
|
case EmptyBracket:
|
||
|
break;
|
||
|
case Integral:
|
||
|
case Sum:
|
||
|
case Product:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void Artwork::draw(TQPainter& painter, const LuPixelRect& ,
|
||
15 years ago
|
const ContextStyle& context, ContextStyle::TextStyle tstyle,
|
||
|
StyleAttributes& style, luPt , const LuPixelPoint& origin)
|
||
|
{
|
||
|
luPt mySize = context.getAdjustedSize( tstyle, style.sizeFactor() );
|
||
|
luPixel myX = origin.x() + getX();
|
||
|
luPixel myY = origin.y() + getY();
|
||
|
/*
|
||
|
if ( !LuPixelRect( myX, myY, getWidth(), getHeight() ).intersects( r ) )
|
||
|
return;
|
||
|
*/
|
||
|
|
||
|
painter.setPen(context.getDefaultColor());
|
||
|
|
||
|
switch (getType()) {
|
||
|
case LeftSquareBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigRoundBracket( painter, context, leftSquareBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case RightSquareBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigRoundBracket( painter, context, rightSquareBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case LeftCurlyBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigCurlyBracket( painter, context, leftCurlyBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case RightCurlyBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigCurlyBracket( painter, context, rightCurlyBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case LeftLineBracket: {
|
||
|
luPixel halfWidth = getWidth()/2;
|
||
|
drawBigRoundBracket( painter, context, leftLineBracket,
|
||
|
myX-halfWidth, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case RightLineBracket: {
|
||
|
luPixel halfWidth = getWidth()/2;
|
||
|
drawBigRoundBracket( painter, context, rightLineBracket,
|
||
|
myX-halfWidth, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case SlashBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case BackSlashBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case LeftCornerBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else drawCharacter(painter, context, myX, myY, mySize, leftAngleBracketChar);
|
||
|
break;
|
||
|
case RightCornerBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else drawCharacter(painter, context, myX, myY, mySize, rightAngleBracketChar);
|
||
|
break;
|
||
|
case LeftRoundBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigRoundBracket( painter, context, leftRoundBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case RightRoundBracket:
|
||
|
if ( cmChar != -1 ) {
|
||
|
drawCMDelimiter( painter, context, myX, myY, mySize );
|
||
|
}
|
||
|
else {
|
||
|
drawBigRoundBracket( painter, context, rightRoundBracket, myX, myY, mySize );
|
||
|
}
|
||
|
break;
|
||
|
case EmptyBracket:
|
||
|
break;
|
||
|
case Integral:
|
||
14 years ago
|
drawCharacter(painter, context, TQFont( "cmex10" ), myX, myY, mySize, cmex_Int);
|
||
15 years ago
|
break;
|
||
|
case Sum:
|
||
14 years ago
|
drawCharacter(painter, context, TQFont( "cmex10" ), myX, myY, mySize, cmex_Sum);
|
||
15 years ago
|
break;
|
||
|
case Product:
|
||
14 years ago
|
drawCharacter(painter, context, TQFont( "cmex10" ), myX, myY, mySize, cmex_Prod);
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
// debug
|
||
14 years ago
|
// painter.setBrush(TQt::NoBrush);
|
||
|
// painter.setPen(TQt::green);
|
||
14 years ago
|
// painter.drawRect( context.layoutUnitToPixelX( myX ),
|
||
|
// context.layoutUnitToPixelY( myY ),
|
||
|
// context.layoutUnitToPixelX( getWidth() ),
|
||
|
// context.layoutUnitToPixelY( getHeight() ) );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void Artwork::calcCharSize( const ContextStyle& style, luPt height, TQChar ch )
|
||
15 years ago
|
{
|
||
|
calcCharSize( style, style.getMathFont(), height, ch );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::drawCharacter( TQPainter& painter, const ContextStyle& style,
|
||
15 years ago
|
luPixel x, luPixel y,
|
||
14 years ago
|
luPt height, TQChar ch )
|
||
15 years ago
|
{
|
||
|
drawCharacter( painter, style, style.getMathFont(), x, y, height, ch );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::calcCharSize( const ContextStyle& style, TQFont f,
|
||
|
luPt height, TQChar c )
|
||
15 years ago
|
{
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitPtToPt( height ) );
|
||
15 years ago
|
//f.setPointSize( height );
|
||
14 years ago
|
TQFontMetrics fm(f);
|
||
15 years ago
|
setWidth( style.ptToLayoutUnitPt( fm.width( c ) ) );
|
||
|
LuPixelRect bound = fm.boundingRect( c );
|
||
|
setHeight( style.ptToLayoutUnitPt( bound.height() ) );
|
||
|
setBaseline( style.ptToLayoutUnitPt( -bound.top() ) );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::drawCharacter( TQPainter& painter, const ContextStyle& style,
|
||
|
TQFont f,
|
||
15 years ago
|
luPixel x, luPixel y, luPt height, uchar c )
|
||
|
{
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitToFontSize( height, false ) );
|
||
15 years ago
|
|
||
|
painter.setFont( f );
|
||
14 years ago
|
painter.drawText( style.layoutUnitToPixelX( x ),
|
||
|
style.layoutUnitToPixelY( y+getBaseline() ),
|
||
14 years ago
|
TQString( TQChar( c ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Artwork::calcRoundBracket( const ContextStyle& style, const TQChar chars[],
|
||
15 years ago
|
luPt height, luPt charHeight )
|
||
|
{
|
||
|
uchar uppercorner = chars[0];
|
||
|
uchar lowercorner = chars[1];
|
||
|
//uchar line = style.symbolTable().character( chars[2] );
|
||
|
|
||
14 years ago
|
TQFont f = style.getBracketFont();
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitPtToPt( charHeight ) );
|
||
14 years ago
|
TQFontMetrics fm( f );
|
||
15 years ago
|
LuPtRect upperBound = fm.boundingRect( uppercorner );
|
||
|
LuPtRect lowerBound = fm.boundingRect( lowercorner );
|
||
|
//LuPtRect lineBound = fm.boundingRect( line );
|
||
|
|
||
14 years ago
|
setWidth( style.ptToLayoutUnitPt( fm.width( TQChar( uppercorner ) ) ) );
|
||
15 years ago
|
luPt edgeHeight = style.ptToLayoutUnitPt( upperBound.height()+lowerBound.height() );
|
||
|
//luPt lineHeight = style.ptToLayoutUnitPt( lineBound.height() );
|
||
|
|
||
|
//setHeight( edgeHeight + ( ( height-edgeHeight-1 ) / lineHeight + 1 ) * lineHeight );
|
||
14 years ago
|
setHeight( TQMAX( edgeHeight, height ) );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void Artwork::drawBigRoundBracket( TQPainter& p, const ContextStyle& style, const TQChar chars[],
|
||
15 years ago
|
luPixel x, luPixel y, luPt charHeight )
|
||
|
{
|
||
|
uchar uppercorner = chars[0];
|
||
|
uchar lowercorner = chars[1];
|
||
|
uchar line = chars[2];
|
||
|
|
||
14 years ago
|
TQFont f = style.getBracketFont();
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitToFontSize( charHeight, false ) );
|
||
15 years ago
|
p.setFont(f);
|
||
|
|
||
14 years ago
|
TQFontMetrics fm(f);
|
||
|
TQRect upperBound = fm.boundingRect(uppercorner);
|
||
|
TQRect lowerBound = fm.boundingRect(lowercorner);
|
||
|
TQRect lineBound = fm.boundingRect(line);
|
||
15 years ago
|
|
||
14 years ago
|
pixel ptX = style.layoutUnitToPixelX( x );
|
||
|
pixel ptY = style.layoutUnitToPixelY( y );
|
||
|
pixel height = style.layoutUnitToPixelY( getHeight() );
|
||
15 years ago
|
|
||
14 years ago
|
// p.setPen( TQt::red );
|
||
15 years ago
|
// //p.drawRect( ptX, ptY, upperBound.width(), upperBound.height() + lowerBound.height() );
|
||
14 years ago
|
// p.drawRect( ptX, ptY, style.layoutUnitToPixelX( getWidth() ),
|
||
|
// style.layoutUnitToPixelY( getHeight() ) );
|
||
15 years ago
|
|
||
14 years ago
|
// p.setPen( TQt::black );
|
||
|
p.drawText( ptX, ptY-upperBound.top(), TQString( TQChar( uppercorner ) ) );
|
||
15 years ago
|
p.drawText( ptX, ptY+height-lowerBound.top()-lowerBound.height(),
|
||
14 years ago
|
TQString( TQChar( lowercorner ) ) );
|
||
15 years ago
|
|
||
|
// for printing
|
||
|
//pt safety = lineBound.height() / 10.0;
|
||
|
pixel safety = 0;
|
||
|
|
||
|
pixel gap = height - upperBound.height() - lowerBound.height();
|
||
|
pixel lineHeight = lineBound.height() - safety;
|
||
14 years ago
|
int lineCount = tqRound( static_cast<double>( gap ) / lineHeight );
|
||
15 years ago
|
pixel start = upperBound.height()-lineBound.top() - safety;
|
||
|
|
||
|
for (int i = 0; i < lineCount; i++) {
|
||
14 years ago
|
p.drawText( ptX, ptY+start+i*lineHeight, TQString(TQChar(line)));
|
||
15 years ago
|
}
|
||
|
pixel remaining = gap - lineCount*lineHeight;
|
||
|
pixel dist = ( lineHeight - remaining ) / 2;
|
||
|
p.drawText( ptX, ptY+height-upperBound.height()+dist-lineBound.height()-lineBound.top(),
|
||
14 years ago
|
TQString( TQChar( line ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void Artwork::calcCurlyBracket( const ContextStyle& style, const TQChar chars[],
|
||
15 years ago
|
luPt height, luPt charHeight )
|
||
|
{
|
||
|
uchar uppercorner = chars[0];
|
||
|
uchar lowercorner = chars[1];
|
||
|
//uchar line = style.symbolTable().character( chars[2] );
|
||
|
uchar middle = chars[3];
|
||
|
|
||
14 years ago
|
TQFont f = style.getBracketFont();
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitPtToPt( charHeight ) );
|
||
14 years ago
|
TQFontMetrics fm( f );
|
||
15 years ago
|
LuPtRect upperBound = fm.boundingRect( uppercorner );
|
||
|
LuPtRect lowerBound = fm.boundingRect( lowercorner );
|
||
|
//LuPtRect lineBound = fm.boundingRect( line );
|
||
|
LuPtRect middleBound = fm.boundingRect( middle );
|
||
|
|
||
14 years ago
|
setWidth( style.ptToLayoutUnitPt( fm.width( TQChar( uppercorner ) ) ) );
|
||
15 years ago
|
luPt edgeHeight = style.ptToLayoutUnitPt( upperBound.height()+
|
||
|
lowerBound.height()+
|
||
|
middleBound.height() );
|
||
|
//luPt lineHeight = style.ptToLayoutUnitPt( lineBound.height() );
|
||
|
|
||
|
//setHeight( edgeHeight + ( ( height-edgeHeight-1 ) / lineHeight + 1 ) * lineHeight );
|
||
14 years ago
|
setHeight( TQMAX( edgeHeight, height ) );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void Artwork::drawBigCurlyBracket( TQPainter& p, const ContextStyle& style, const TQChar chars[],
|
||
15 years ago
|
luPixel x, luPixel y, luPt charHeight )
|
||
|
{
|
||
14 years ago
|
//TQFont f = style.getSymbolFont();
|
||
|
TQFont f = style.getBracketFont();
|
||
14 years ago
|
f.setPointSizeFloat( style.layoutUnitToFontSize( charHeight, false ) );
|
||
15 years ago
|
p.setFont(f);
|
||
|
|
||
|
uchar uppercorner = chars[0];
|
||
|
uchar lowercorner = chars[1];
|
||
|
uchar line = chars[2];
|
||
|
uchar middle = chars[3];
|
||
|
|
||
14 years ago
|
TQFontMetrics fm(p.fontMetrics());
|
||
|
TQRect upperBound = fm.boundingRect(uppercorner);
|
||
|
TQRect lowerBound = fm.boundingRect(lowercorner);
|
||
|
TQRect middleBound = fm.boundingRect(middle);
|
||
|
TQRect lineBound = fm.boundingRect(line);
|
||
15 years ago
|
|
||
14 years ago
|
pixel ptX = style.layoutUnitToPixelX( x );
|
||
|
pixel ptY = style.layoutUnitToPixelY( y );
|
||
|
pixel height = style.layoutUnitToPixelY( getHeight() );
|
||
15 years ago
|
|
||
14 years ago
|
//p.setPen(TQt::gray);
|
||
15 years ago
|
//p.drawRect(x, y, upperBound.width() + offset, height);
|
||
|
|
||
14 years ago
|
p.drawText( ptX, ptY-upperBound.top(), TQString( TQChar( uppercorner ) ) );
|
||
15 years ago
|
p.drawText( ptX, ptY+(height-middleBound.height())/2-middleBound.top(),
|
||
14 years ago
|
TQString( TQChar( middle ) ) );
|
||
15 years ago
|
p.drawText( ptX, ptY+height-lowerBound.top()-lowerBound.height(),
|
||
14 years ago
|
TQString( TQChar( lowercorner ) ) );
|
||
15 years ago
|
|
||
|
// for printing
|
||
|
// If the world was perfect and the urw-symbol font correct
|
||
|
// this could be 0.
|
||
|
//lu safety = lineBound.height() / 10;
|
||
|
pixel safety = 0;
|
||
|
|
||
|
pixel lineHeight = lineBound.height() - safety;
|
||
|
pixel gap = height/2 - upperBound.height() - middleBound.height() / 2;
|
||
|
|
||
|
if (gap > 0) {
|
||
14 years ago
|
TQString ch = TQString(TQChar(line));
|
||
|
int lineCount = tqRound( gap / lineHeight ) + 1;
|
||
15 years ago
|
|
||
|
pixel start = (height - middleBound.height()) / 2 + safety;
|
||
|
for (int i = 0; i < lineCount; i++) {
|
||
14 years ago
|
p.drawText( ptX, ptY-lineBound.top()+TQMAX( start-(i+1)*lineHeight,
|
||
15 years ago
|
upperBound.width() ),
|
||
|
ch );
|
||
|
}
|
||
|
|
||
|
start = (height + middleBound.height()) / 2 - safety;
|
||
|
for (int i = 0; i < lineCount; i++) {
|
||
14 years ago
|
p.drawText( ptX, ptY-lineBound.top()+TQMIN( start+i*lineHeight,
|
||
15 years ago
|
height-upperBound.width()-lineBound.height() ),
|
||
|
ch );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KFORMULA_NAMESPACE_END
|