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

« back to all changes in this revision

Viewing changes to filters/kword/amipro/amiproparser.cpp

  • 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:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2002 Ariya Hidayat <ariyahidayat@yahoo.de>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "amiproparser.h"
 
21
 
 
22
#include <qfile.h>
 
23
#include <qstring.h>
 
24
#include <qstringlist.h>
 
25
#include <qtextstream.h>
 
26
 
 
27
const float AmiPro::LS_Single = -1;
 
28
const float AmiPro::LS_OneAndHalf = -1.5;
 
29
const float AmiPro::LS_Double = -2;
 
30
 
 
31
// helper function to "unescape" AmiPro string
 
32
static QString AmiProUnescape( const QString& str )
 
33
{
 
34
  QString result;
 
35
 
 
36
  for( unsigned i=0; i< str.length(); i++ )
 
37
  {
 
38
    QChar c = str[i];
 
39
    result.append( c );
 
40
 
 
41
    // check for "@@", decoded as '@'
 
42
    if( c == '@' )
 
43
      if( str[i+1] == '@' )
 
44
         i++ ; // eat !
 
45
 
 
46
    // a few possible escape sequence
 
47
    if( c == '<'  )
 
48
    {
 
49
 
 
50
      // check for "<<", decoded as '<'
 
51
      if( str[i+1] == '<' )
 
52
      {
 
53
        result.truncate( result.length() - 1 ); // remove the '<'
 
54
        result.append( '<' );
 
55
        i++;
 
56
      }
 
57
 
 
58
      // check for "<;>", decoded as '>'
 
59
      if( str[i+1] == ';' )
 
60
      {
 
61
        result.truncate( result.length() - 1 ); // remove the '<'
 
62
        result.append( '>' );
 
63
        i+=2;
 
64
      }
 
65
 
 
66
      // check for "<[>", decoded as '['
 
67
      if( str[i+1] == '[' )
 
68
      {
 
69
        result.truncate( result.length() - 1 ); // remove the '<'
 
70
        result.append( '[' );
 
71
        i+=2;
 
72
      }
 
73
 
 
74
      // some special characters
 
75
      if( str[i+1] == '/' )
 
76
      {
 
77
        result.truncate( result.length() - 1 ); // remove the '<'
 
78
        result.append( QChar(str[i+2].unicode() + 0x40 ) );
 
79
        i += 3;
 
80
      }
 
81
 
 
82
      // yet another special characters
 
83
      if( str[i+1] == '\\' )
 
84
      {
 
85
        result.truncate( result.length() - 1 ); // remove the '<'
 
86
        result.append( QChar(str[i+2].unicode() | 0x80 ) );
 
87
        i += 3;
 
88
      }
 
89
 
 
90
    }
 
91
 
 
92
  }
 
93
 
 
94
  return result;
 
95
}
 
96
 
 
97
AmiProParser::AmiProParser()
 
98
{
 
99
  m_result = OK;
 
100
  m_listener = NULL;
 
101
}
 
102
 
 
103
AmiProParser::~AmiProParser()
 
104
{
 
105
}
 
106
 
 
107
bool AmiProParser::setResult( int result )
 
108
{
 
109
  m_result = result;
 
110
  return m_result == OK;
 
111
}
 
112
 
 
113
void AmiProParser::setListener( AmiProListener *listener )
 
114
{
 
115
  m_listener = listener;
 
116
}
 
117
 
 
118
bool AmiProParser::process( const QString& filename )
 
119
{
 
120
  QString line;
 
121
 
 
122
  // open input file
 
123
  QFile in( filename );
 
124
  if( !in.open( IO_ReadOnly))
 
125
    return setResult( FileError );
 
126
 
 
127
  QTextStream stream;
 
128
  stream.setDevice( &in );
 
129
 
 
130
  // the first should be "[ver]"
 
131
  line = stream.readLine();
 
132
  if( line != "[ver]" ) 
 
133
    return setResult( InvalidFormat ); 
 
134
 
 
135
  // get format version, typically 4 
 
136
  line = stream.readLine();
 
137
  int format_version = line.toInt();
 
138
 
 
139
  // FIXME is this necessary ?
 
140
  // accept only format version 4
 
141
  if( format_version != 4 )
 
142
    return setResult( InvalidFormat );
 
143
 
 
144
  // initialize
 
145
  m_currentFormat = AmiProFormat();
 
146
  m_formatList.clear();
 
147
  m_styleList.clear();
 
148
  m_currentSection = "";
 
149
  QStringList lines;
 
150
 
 
151
  // parse line-by-line
 
152
  for( ;; )
 
153
  {
 
154
 
 
155
    line = stream.readLine();
 
156
    if( line.isNull() ) break;
 
157
 
 
158
    QString old_section = m_currentSection;
 
159
    bool enter_new_section = false;
 
160
 
 
161
    // new main section ?
 
162
    if( !line.isEmpty() ) if( line[0] == '[' )
 
163
    {
 
164
      enter_new_section = true;
 
165
      m_currentSection = "";
 
166
      for( unsigned i=1; i<line.length(); i++ )
 
167
        if( line[i] == ']' ) break;
 
168
        else m_currentSection += line[i];
 
169
    }
 
170
 
 
171
    // leave [tag]
 
172
    if( enter_new_section && ( old_section == "tag" ) )
 
173
    {
 
174
      parseStyle( lines );
 
175
      lines.clear();
 
176
    }
 
177
 
 
178
    // leave [edoc]
 
179
    if( enter_new_section && ( old_section == "edoc" ) )
 
180
    {
 
181
      parseParagraph( lines.join(" ") );
 
182
      lines.clear();
 
183
    }
 
184
 
 
185
    // still in [tag]
 
186
    if( !enter_new_section && ( old_section == "tag" ) )
 
187
    {
 
188
      lines.append( line );
 
189
    } 
 
190
 
 
191
    // still in [edoc]
 
192
    if( !enter_new_section && ( old_section == "edoc" ) )
 
193
    {
 
194
      if( line.isEmpty() ) 
 
195
      {
 
196
         parseParagraph( lines );
 
197
         lines.clear(); 
 
198
      }
 
199
        lines.append( line );
 
200
    }
 
201
 
 
202
    // enter [tag]
 
203
    if( enter_new_section && ( m_currentSection == "tag" ) )
 
204
    {
 
205
      lines.clear();
 
206
    }
 
207
 
 
208
    // enter [edoc]
 
209
    if( enter_new_section && ( m_currentSection == "edoc" ) )
 
210
    {
 
211
      processOpenDocument();
 
212
      lines.clear();
 
213
    }
 
214
 
 
215
  }
 
216
 
 
217
  // in case left-over
 
218
  if( lines.count() > 0 ) parseParagraph( lines.join( " " ) );
 
219
 
 
220
  processCloseDocument();
 
221
 
 
222
  return true;
 
223
}
 
224
 
 
225
bool AmiProParser::processOpenDocument()
 
226
{
 
227
  if( m_listener ) return m_listener->doOpenDocument();
 
228
  return true;
 
229
}
 
230
 
 
231
bool AmiProParser::processCloseDocument()
 
232
{
 
233
  if( m_listener ) 
 
234
    return m_listener->doCloseDocument();
 
235
  return true;
 
236
}
 
237
 
 
238
bool AmiProParser::parseParagraph( const QStringList& lines )
 
239
{
 
240
  m_text = "";
 
241
  m_formatList.clear();
 
242
  m_layout = AmiProLayout();
 
243
 
 
244
  // join the lines, up until first char in a line is '>'
 
245
  QString partext = "";
 
246
  for( unsigned i=0; i<lines.count(); i++ )
 
247
    if( lines[i][0] == '>' ) break;
 
248
      else partext.append( lines[i] + "\n" );
 
249
 
 
250
  QChar ch = partext[partext.length()-1];
 
251
  while( ( ch == '\n' ) || ( ch == '\r' ) )
 
252
  {
 
253
    partext.remove( partext.length()-1, 1 );
 
254
    ch = partext[partext.length()-1];
 
255
  }
 
256
 
 
257
  // "unescape", process special chars and such
 
258
  QString text = AmiProUnescape( partext );
 
259
 
 
260
  // apply default style first
 
261
  m_layout.applyStyle( findStyle( "Body Text" ) );
 
262
 
 
263
  for( unsigned i=0; i<text.length(); i++ )
 
264
  {
 
265
    QChar ch = text[i];
 
266
 
 
267
    // handle a tag
 
268
    if( ch == '<' )
 
269
    {
 
270
        QString tag = "";
 
271
        for( i++; (i < text.length()) && 
 
272
           (text[i] != '>'); i++) tag.append( text[i] );
 
273
        handleTag( tag );
 
274
    }
 
275
 
 
276
    else
 
277
 
 
278
    // handle style change
 
279
    if( ch == '@' )
 
280
    {
 
281
        QString styleName;
 
282
        for( i++; (i < partext.length()) && (partext[i] != '@'); i++)
 
283
          styleName += partext[i];
 
284
        m_layout.name = styleName;
 
285
        AmiProStyle style = findStyle( styleName );
 
286
        m_currentFormat.applyStyle( style );
 
287
        m_formatList.append( m_currentFormat ); 
 
288
        m_layout.applyStyle( style );
 
289
    }
 
290
 
 
291
     else 
 
292
       // normal character
 
293
       m_text.append( ch ); 
 
294
  }
 
295
 
 
296
  // calc length of each format tag
 
297
  for( unsigned j=0; j<m_formatList.count(); j++ )
 
298
  {
 
299
    int nextpos;
 
300
    AmiProFormat& format = m_formatList[j];
 
301
    if( j < m_formatList.count()-1 )
 
302
    {
 
303
      AmiProFormat& nextformat = m_formatList[j+1];
 
304
      nextpos = nextformat.pos;
 
305
    }
 
306
    else  nextpos = m_text.length();
 
307
    format.len = nextpos - format.pos;
 
308
  }
 
309
 
 
310
  if( m_listener ) 
 
311
    return m_listener->doParagraph( m_text, m_formatList, m_layout );
 
312
 
 
313
  return true;
 
314
}
 
315
 
 
316
bool AmiProParser::parseStyle( const QStringList& lines )
 
317
{
 
318
  AmiProStyle style;
 
319
 
 
320
  style.name = AmiProUnescape( lines[0].stripWhiteSpace() );
 
321
  if( style.name.isEmpty() ) return true;
 
322
 
 
323
  // font
 
324
  if( lines[2].stripWhiteSpace() != "[fnt]" ) return true;
 
325
  style.fontFamily = lines[3].stripWhiteSpace();
 
326
  style.fontSize = lines[4].stripWhiteSpace().toFloat() / 20.0;
 
327
 
 
328
  unsigned color = lines[5].stripWhiteSpace().toUInt();
 
329
  style.fontColor.setRgb( color&255, (color>>8)&255, (color>>16)&255);
 
330
 
 
331
  unsigned flag = lines[6].stripWhiteSpace().toUInt();
 
332
  style.bold = flag & 1;
 
333
  style.italic = flag & 2;
 
334
  style.underline = flag & 4;
 
335
  style.word_underline = flag & 8;
 
336
  style.double_underline = flag & 64;
 
337
 
 
338
  // alignment
 
339
  if( lines[7].stripWhiteSpace() != "[algn]" ) return true;
 
340
  unsigned align_flag = lines[8].stripWhiteSpace().toUInt();
 
341
  if( align_flag & 1 ) style.align = Qt::AlignLeft;
 
342
  if( align_flag & 2 ) style.align = Qt::AlignRight;
 
343
  if( align_flag & 4 ) style.align = Qt::AlignCenter;
 
344
  if( align_flag & 8 ) style.align = Qt::AlignJustify;
 
345
 
 
346
  // linespace
 
347
  if( lines[13].stripWhiteSpace() != "[spc]" ) return true;
 
348
  unsigned ls_flag = lines[14].stripWhiteSpace().toUInt();
 
349
  if( ls_flag & 1 ) style.linespace = AmiPro::LS_Single;
 
350
  if( ls_flag & 2 ) style.linespace = AmiPro::LS_OneAndHalf;
 
351
  if( ls_flag & 4 ) style.linespace = AmiPro::LS_Double;
 
352
  if( ls_flag & 8 ) 
 
353
    style.linespace = lines[15].stripWhiteSpace().toFloat() / 20.0;
 
354
  style.spaceBefore = lines[17].stripWhiteSpace().toFloat() / 20.0;
 
355
  style.spaceAfter = lines[18].stripWhiteSpace().toFloat() / 20.0;
 
356
 
 
357
  m_styleList.append( style );
 
358
 
 
359
  // "Style #0", "Style #1" and such are special styles
 
360
  // do not import these styles
 
361
  if( style.name.left( 7 ) != "Style #" )
 
362
  if( m_listener )
 
363
    return m_listener->doDefineStyle( style );
 
364
  return true;
 
365
}
 
366
 
 
367
AmiProStyle AmiProParser::findStyle( const QString& name )
 
368
{
 
369
  AmiProStyleList::iterator it;
 
370
  for( it=m_styleList.begin(); it!=m_styleList.end(); ++it )
 
371
  {
 
372
    AmiProStyle& style = *it;
 
373
    if( style.name == name )
 
374
      return style;
 
375
  }
 
376
  return AmiProStyle();
 
377
}
 
378
 
 
379
bool AmiProParser::handleTag( const QString& tag )
 
380
{
 
381
  // > (actually encoded as <;>)
 
382
  if( tag == ";" )
 
383
    m_text.append( ">" );
 
384
 
 
385
  // [ (actually encoded as <[>)
 
386
  if( tag == "[" )
 
387
    m_text.append( "[" );
 
388
 
 
389
  // bold on
 
390
  if( tag == "+!" )
 
391
  {
 
392
    m_currentFormat.bold = true;
 
393
    m_currentFormat.pos = m_text.length();
 
394
    m_formatList.append( m_currentFormat );
 
395
  }
 
396
 
 
397
  // bold off
 
398
  if( tag == "-!" )
 
399
  {
 
400
    m_currentFormat.bold = false;
 
401
    m_currentFormat.pos = m_text.length();
 
402
    m_formatList.append( m_currentFormat );
 
403
  }
 
404
 
 
405
  // italic on
 
406
  if( tag == "+\"" )
 
407
  {
 
408
    m_currentFormat.italic = true;
 
409
    m_currentFormat.pos = m_text.length();
 
410
    m_formatList.append( m_currentFormat );
 
411
  }
 
412
 
 
413
  // italic off
 
414
  if( tag == "-\"" )
 
415
  {
 
416
    m_currentFormat.italic = false;
 
417
    m_currentFormat.pos = m_text.length();
 
418
    m_formatList.append( m_currentFormat );
 
419
  }
 
420
 
 
421
  // underline on
 
422
  if( tag == "+#" )
 
423
  {
 
424
    m_currentFormat.underline = true;
 
425
    m_currentFormat.pos = m_text.length();
 
426
    m_formatList.append( m_currentFormat );
 
427
  }
 
428
 
 
429
  // underline off
 
430
  if( tag == "-#" )
 
431
  {
 
432
    m_currentFormat.underline = false;
 
433
    m_currentFormat.pos = m_text.length();
 
434
    m_formatList.append( m_currentFormat );
 
435
  }
 
436
 
 
437
  // double underline on
 
438
  if( tag == "+)" )
 
439
  {
 
440
    m_currentFormat.double_underline = true; 
 
441
    m_currentFormat.pos = m_text.length();
 
442
    m_formatList.append( m_currentFormat );
 
443
  }
 
444
 
 
445
  // double underline off
 
446
  if( tag == "-)" )
 
447
  {
 
448
    m_currentFormat.double_underline = false;
 
449
    m_currentFormat.pos = m_text.length();
 
450
    m_formatList.append( m_currentFormat );
 
451
  }
 
452
 
 
453
 // word underline on
 
454
  if( tag == "+$" )
 
455
  {
 
456
    m_currentFormat.word_underline = true; 
 
457
    m_currentFormat.pos = m_text.length();
 
458
    m_formatList.append( m_currentFormat );
 
459
  }
 
460
 
 
461
  // word underline off
 
462
  if( tag == "-$" )
 
463
  {
 
464
    m_currentFormat.word_underline = false;
 
465
    m_currentFormat.pos = m_text.length();
 
466
    m_formatList.append( m_currentFormat );
 
467
  }
 
468
 
 
469
  // superscript on
 
470
  if( tag == "+&" )
 
471
  {
 
472
    m_currentFormat.superscript = true; 
 
473
    m_currentFormat.pos = m_text.length();
 
474
    m_formatList.append( m_currentFormat );
 
475
  }
 
476
 
 
477
  // superscript off
 
478
  if( tag == "-&" )
 
479
  {
 
480
    m_currentFormat.superscript = false;
 
481
    m_currentFormat.pos = m_text.length();
 
482
    m_formatList.append( m_currentFormat );
 
483
  }
 
484
 
 
485
  // subscript on
 
486
  if( tag == "+'" )
 
487
  {
 
488
    m_currentFormat.subscript = true;
 
489
    m_currentFormat.pos = m_text.length();
 
490
    m_formatList.append( m_currentFormat );
 
491
  }
 
492
 
 
493
  // subscript off
 
494
  if( tag == "-'" )
 
495
  {
 
496
    m_currentFormat.subscript = false;
 
497
    m_currentFormat.pos = m_text.length();
 
498
    m_formatList.append( m_currentFormat );
 
499
  }
 
500
 
 
501
  // strikethrough on
 
502
  if( tag == "+%" )
 
503
  {
 
504
    m_currentFormat.strikethrough = true;
 
505
    m_currentFormat.pos = m_text.length();
 
506
    m_formatList.append( m_currentFormat );
 
507
  }
 
508
 
 
509
  // strikethrough off
 
510
  if( tag == "-%" )
 
511
  {
 
512
    m_currentFormat.strikethrough = false;
 
513
    m_currentFormat.pos = m_text.length();
 
514
    m_formatList.append( m_currentFormat );
 
515
  }
 
516
 
 
517
  // paragraph left-align
 
518
  if( tag == "+@" )
 
519
    m_layout.align = Qt::AlignLeft;
 
520
 
 
521
  // paragraph right-align
 
522
  if( tag == "+A" )
 
523
    m_layout.align = Qt::AlignRight;
 
524
 
 
525
  // paragraph center
 
526
  if( tag == "+B" )
 
527
    m_layout.align = Qt::AlignCenter;
 
528
 
 
529
  // paragraph justify
 
530
  if( tag == "+C" )
 
531
    m_layout.align = Qt::AlignJustify;
 
532
 
 
533
  // linespace
 
534
  if( tag.left( 3 ) == ":S+" )
 
535
  {
 
536
    float ls = tag.right( tag.length() - 3 ).toFloat();
 
537
    m_layout.linespace = (ls == -1) ? AmiPro::LS_Single :
 
538
     (ls == -2) ? AmiPro::LS_OneAndHalf :
 
539
     (ls == -3) ? AmiPro::LS_Double : ls / 20.0;
 
540
  }
 
541
 
 
542
  // font
 
543
  if( tag.left( 2 ) == ":f" )
 
544
  {
 
545
    QString fontdesc = tag.right( tag.length()-2 );
 
546
    QStringList desc = QStringList::split( ",", fontdesc );
 
547
    if( desc.count() > 0 ) m_currentFormat.fontSize = desc[0].toFloat() / 20.0;
 
548
    if( desc.count() > 1 )
 
549
    {
 
550
      QString fontFamily = desc[1];
 
551
      if( fontFamily[0].isDigit() ) fontFamily.remove( 0, 1 );
 
552
      m_currentFormat.fontFamily = fontFamily;
 
553
    }
 
554
    if( desc.count() > 4 )
 
555
    {
 
556
      unsigned red = desc[2].toUInt();
 
557
      unsigned green = desc[3].toUInt();
 
558
      unsigned blue = desc[4].toUInt();
 
559
      m_currentFormat.fontColor.setRgb( red, green, blue );
 
560
    }
 
561
    m_formatList.append( m_currentFormat );
 
562
  }
 
563
 
 
564
  return true;
 
565
}
 
566
 
 
567
// text formatting
 
568
AmiProFormat::AmiProFormat()
 
569
{
 
570
  pos = len = 0;
 
571
  bold = italic = underline = 
 
572
  word_underline = double_underline = 
 
573
  subscript = superscript = strikethrough = FALSE;
 
574
  fontFamily = "";
 
575
  fontSize = 12;
 
576
  fontColor = Qt::black;
 
577
}
 
578
 
 
579
void AmiProFormat::assign( const AmiProFormat& f )
 
580
{
 
581
  pos = f.pos;
 
582
  len = f.len;
 
583
  bold = f.bold;
 
584
  italic = f.italic;
 
585
  underline = f.underline;
 
586
  word_underline = f.word_underline;
 
587
  double_underline = f.double_underline;
 
588
  subscript = f.subscript;
 
589
  superscript = f.superscript;
 
590
  strikethrough = f.strikethrough;
 
591
  fontFamily = f.fontFamily;
 
592
  fontSize = f.fontSize;
 
593
  fontColor = f.fontColor;
 
594
}
 
595
 
 
596
AmiProFormat::AmiProFormat( const AmiProFormat& f )
 
597
{
 
598
  assign( f );
 
599
}
 
600
 
 
601
AmiProFormat& AmiProFormat::operator=(  const AmiProFormat& f )
 
602
{
 
603
  assign( f );
 
604
  return *this;
 
605
}
 
606
 
 
607
void AmiProFormat::applyStyle( const AmiProStyle& style )
 
608
{
 
609
  fontFamily = style.fontFamily;
 
610
  fontSize = style.fontSize;
 
611
  fontColor = style.fontColor;
 
612
  bold = style.bold;
 
613
  italic = style.italic;
 
614
  underline = style.underline;
 
615
  word_underline = style.word_underline;
 
616
  double_underline = style.double_underline;
 
617
  subscript = style.subscript;
 
618
  superscript = style.superscript;
 
619
  strikethrough = style.strikethrough;
 
620
}
 
621
 
 
622
// paragraph layout
 
623
AmiProLayout::AmiProLayout()
 
624
{
 
625
  name = "";
 
626
  fontFamily = "";
 
627
  fontSize = 12;
 
628
  fontColor = Qt::black;
 
629
  bold = italic = underline = 
 
630
  word_underline = double_underline = 
 
631
  subscript = superscript = strikethrough = FALSE;
 
632
  align = Qt::AlignLeft;
 
633
  linespace = AmiPro::LS_Single;
 
634
  spaceBefore = spaceAfter = 0;
 
635
}
 
636
 
 
637
void AmiProLayout::assign( const AmiProLayout &l )
 
638
{
 
639
  name = l.name;
 
640
  fontFamily = l.fontFamily;
 
641
  fontSize = l.fontSize;
 
642
  fontColor = l.fontColor;
 
643
  bold = l.bold;
 
644
  italic = l.italic;
 
645
  underline = l.underline;
 
646
  word_underline = l.word_underline;
 
647
  double_underline = l.double_underline;
 
648
  subscript = l.subscript;
 
649
  superscript = l.superscript;
 
650
  strikethrough = l.strikethrough;
 
651
  align = l.align;
 
652
  linespace = l.linespace;
 
653
  spaceBefore = l.spaceBefore;
 
654
  spaceAfter = l.spaceAfter;
 
655
}
 
656
 
 
657
AmiProLayout::AmiProLayout( const AmiProLayout& l )
 
658
{
 
659
  assign( l );
 
660
}
 
661
 
 
662
AmiProLayout& AmiProLayout::operator=( const AmiProLayout& l )
 
663
{
 
664
  assign( l );
 
665
  return *this;
 
666
}
 
667
 
 
668
void AmiProLayout::applyStyle( const AmiProStyle& style )
 
669
{
 
670
  fontFamily = style.fontFamily;
 
671
  fontSize = style.fontSize;
 
672
  fontColor = style.fontColor;
 
673
  bold = style.bold;
 
674
  italic = style.italic;
 
675
  underline = style.underline;
 
676
  word_underline = style.word_underline;
 
677
  double_underline = style.double_underline;
 
678
  subscript = style.subscript;
 
679
  superscript = style.superscript;
 
680
  strikethrough = style.strikethrough;
 
681
  align = style.align;
 
682
  linespace = style.linespace;
 
683
  spaceBefore = style.spaceBefore;
 
684
  spaceAfter = style.spaceAfter;
 
685
}
 
686
 
 
687
// style definition
 
688
AmiProStyle::AmiProStyle()
 
689
{
 
690
  name = "Unnamed";
 
691
  fontFamily = "";
 
692
  fontSize = 12;
 
693
  fontColor = Qt::black;
 
694
  bold = italic = underline = 
 
695
  word_underline = double_underline = 
 
696
  subscript = superscript = strikethrough = FALSE;
 
697
  linespace = AmiPro::LS_Single;
 
698
  spaceBefore = spaceAfter = 0;
 
699
}
 
700
 
 
701
void AmiProStyle::assign( const AmiProStyle& s )
 
702
{
 
703
  name = s.name;
 
704
  fontFamily = s.fontFamily;
 
705
  fontSize = s.fontSize;
 
706
  fontColor = s.fontColor;
 
707
  bold = s.bold;
 
708
  italic = s.italic;
 
709
  underline = s.underline;
 
710
  word_underline = s.word_underline;
 
711
  double_underline = s.double_underline;
 
712
  subscript = s.subscript;
 
713
  superscript = s.superscript;
 
714
  strikethrough = s.strikethrough;
 
715
  align = s.align;
 
716
  linespace = s.linespace;
 
717
  spaceBefore = s.spaceBefore;
 
718
  spaceAfter = s.spaceAfter;
 
719
}
 
720
 
 
721
AmiProStyle::AmiProStyle( const AmiProStyle& s )
 
722
{
 
723
  assign( s );
 
724
}
 
725
 
 
726
AmiProStyle& AmiProStyle::operator=( const AmiProStyle& s )
 
727
{
 
728
  assign( s );
 
729
  return *this;
 
730
}
 
731
 
 
732
// base listener for the parser
 
733
AmiProListener::AmiProListener()
 
734
{
 
735
}
 
736
 
 
737
AmiProListener::~AmiProListener()
 
738
{
 
739
}
 
740
 
 
741
#define DO_TRUE_DEFINITION(string) \
 
742
    bool AmiProListener::string \
 
743
    {\
 
744
        return true;\
 
745
    }
 
746
 
 
747
DO_TRUE_DEFINITION(doOpenDocument())
 
748
DO_TRUE_DEFINITION(doCloseDocument())
 
749
DO_TRUE_DEFINITION(doDefineStyle(const AmiProStyle& style))
 
750
DO_TRUE_DEFINITION(doParagraph(const QString& text, AmiProFormatList formatList,
 
751
  AmiProLayout& ))