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

« back to all changes in this revision

Viewing changes to lib/kformula/kformulamimesource.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:
5
5
   This library is free software; you can redistribute it and/or
6
6
   modify it under the terms of the GNU Library General Public
7
7
   License as published by the Free Software Foundation; either
8
 
   version 2 of the License.
 
8
   version 2 of the License, or (at your option) any later version.
9
9
 
10
10
   This library is distributed in the hope that it will be useful,
11
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
32
32
#include "contextstyle.h"
33
33
#include "formulacursor.h"
34
34
#include "formulaelement.h"
 
35
#include "kformuladocument.h"
35
36
#include "kformulamimesource.h"
36
37
 
37
38
KFORMULA_NAMESPACE_BEGIN
38
39
using namespace std;
39
40
 
40
41
 
41
 
KFormulaMimeSource::KFormulaMimeSource(QDomDocument formula)
42
 
        : document(formula)
 
42
MimeSource::MimeSource(Document* doc, QDomDocument formula)
 
43
        : formulaDocument( doc ), document(formula)
43
44
{
44
45
    // The query for text/plain comes very often. So make sure
45
46
    // it's fast.
47
48
    rootElement = new FormulaElement(this);
48
49
    FormulaCursor cursor(rootElement);
49
50
 
50
 
    QList<BasicElement> list;
 
51
    QPtrList<BasicElement> list;
51
52
    list.setAutoDelete(true);
52
 
    if (cursor.buildElementsFromDom(document, list)) {
 
53
    if ( cursor.buildElementsFromDom( document.documentElement(), list ) ) {
53
54
        cursor.insert(list);
54
55
        latexString = rootElement->toLatex().utf8();
55
56
        if (latexString.size() > 0) {
58
59
    }
59
60
}
60
61
 
61
 
KFormulaMimeSource::~KFormulaMimeSource()
 
62
MimeSource::~MimeSource()
62
63
{
63
64
    delete rootElement;
64
65
}
65
66
 
 
67
const char * MimeSource::selectionMimeType()
 
68
{
 
69
    return "application/x-kformula";
 
70
}
66
71
 
67
 
const char* KFormulaMimeSource::format( int n ) const
 
72
const char* MimeSource::format( int n ) const
68
73
{
69
74
    switch (n) {
70
75
        case 0:
71
 
            return "application/x-kformula";
 
76
            return selectionMimeType();
72
77
        case 1:
73
78
            return "image/ppm";
74
79
        case 2:
79
84
    return NULL;
80
85
}
81
86
 
82
 
bool KFormulaMimeSource::provides( const char * format) const
 
87
bool MimeSource::provides( const char * format) const
83
88
{
84
89
//This is not completed
85
 
    if(QString(format)=="application/x-kformula")
 
90
    if(QString(format)==selectionMimeType())
86
91
        return true;
87
92
    else if(QString(format)=="image/ppm")
88
93
        return true;
94
99
        return false;
95
100
}
96
101
 
97
 
QByteArray KFormulaMimeSource::encodedData ( const char *format ) const
 
102
QByteArray MimeSource::encodedData ( const char *format ) const
98
103
{
99
104
    QString fmt=format;  //case sensitive?
100
105
 
101
106
    if ((fmt=="text/plain") || (fmt=="text/x-tex"))
102
107
        return latexString;
103
108
 
104
 
    if (fmt=="application/x-kformula") {
 
109
    if (fmt==selectionMimeType()) {
105
110
        QByteArray d=document.toCString();
106
111
        d.truncate(d.size()-1);
107
112
        return d;
110
115
    if (fmt=="image/ppm") {
111
116
 
112
117
        //cerr << "asking image" << endl;
113
 
        ContextStyle context;
114
 
        context.setResolution(5, 5);
 
118
        ContextStyle& context = formulaDocument->getContextStyle( false );
 
119
        //context.setResolution(5, 5);
115
120
 
116
121
        rootElement->calcSizes(context);
117
122
        QRect rect(rootElement->getX(), rootElement->getY(),
118
123
                   rootElement->getWidth(), rootElement->getHeight());
119
124
 
120
 
        QPixmap pm(rect.width(),rect.height());
 
125
        QPixmap pm( context.layoutUnitToPixelX( rootElement->getWidth() ),
 
126
                    context.layoutUnitToPixelY( rootElement->getHeight() ) );
121
127
        pm.fill();
122
128
        QPainter paint(&pm);
123
129
        rootElement->draw(paint, rect, context);
140
146
    return QByteArray();
141
147
}
142
148
 
143
 
void KFormulaMimeSource::elementRemoval(BasicElement*)
144
 
{
145
 
}
146
 
 
147
 
void KFormulaMimeSource::changed()
148
 
{
149
 
}
150
 
 
151
 
const SymbolTable& KFormulaMimeSource::getSymbolTable() const
152
 
{
153
 
    return table;
 
149
const SymbolTable& MimeSource::getSymbolTable() const
 
150
{
 
151
    return formulaDocument->getContextStyle( false ).symbolTable();
154
152
}
155
153
 
156
154
KFORMULA_NAMESPACE_END