-
Notifications
You must be signed in to change notification settings - Fork 0
/
stylesheetdestination.cpp
executable file
·136 lines (125 loc) · 2.92 KB
/
stylesheetdestination.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*Copyright 2001
*
* stylesheetdestination.cpp
*
* Author: Gregory Ford [email protected]
* RTF token parser based on:
* rtf2html by Dmitry Porapov <[email protected]>,
* based on earlier work of Chuck Shotton.
* distributed under BSD-style license
* RTF token lists and hashing algorithm based on
* RTF Tools, Release 1.10
* 6 April 1994
* Paul DuBois [email protected]
*
* Copying permitted under GNU licence (see COPYING)
*/
// stylesheetdestination.cpp: implementation of the StyleSheetDestination class.
//
//////////////////////////////////////////////////////////////////////
#include <string>
using namespace std;
#include "tag.h"
#include "token.h"
#include "stylemap.h"
#include "charsource.h"
#include "tokeniser.h"
#include "destination.h"
#include "stylesheetdestination.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
StyleSheetDestination::StyleSheetDestination()
{
groupLevel = 0 ;
currentStyleNum = 0;
}
StyleSheetDestination::~StyleSheetDestination()
{
}
bool StyleSheetDestination::handleToken(Token *token)
{
switch ( token->getType() ) {
case groupToken:
{
GroupToken *g = (GroupToken *)token;
if ( g->group == startGroup ) {
groupLevel++;
} else {
groupLevel--;
if ( groupLevel == 0 ) {
AddCurrentStyleToMap();
currentStyleName = "";
currentStyleNum = 0;
}
}
if (groupLevel <0) {
groupLevel = 0; // reinitialise this object
// ready for reusing on another group!
return true;
}
break;
}
case controlToken:
{
ControlToken *c = (ControlToken *) token;
if ( c->rtfMajor == rtfParAttr && c->rtfMinor == rtfStyleNum ) {
currentStyleNum = c->arg;
}
break;
}
case charToken:
{
currentStyleName += token->text;
break;
}
default:
break;
}
return false;
}
void StyleSheetDestination::setStyleMap(StyleMap *map)
{
styleMap = map;
}
void StyleSheetDestination::AddCurrentStyleToMap()
{
if ( currentStyleName.find_last_of( ';' ) == currentStyleName.size() -1 ) {
currentStyleName = currentStyleName.substr( 0, currentStyleName.size() - 1 );
}
// potentially get error for "heading 10" ---> interpreted as heading 1
if ( currentStyleName.size() > 8 ) {
string s = currentStyleName.substr(0,8) ;
if ( currentStyleName.substr(0,8) == "heading " ) {
switch ( currentStyleName[8] ) {
case '1':
{
styleMap->setStyle( h1Tag, currentStyleNum );
break;
}
case '2':
{
styleMap->setStyle( h2Tag, currentStyleNum );
break;
}
case '3':
{
styleMap->setStyle( h3Tag, currentStyleNum );
break;
}
case '4':
{
styleMap->setStyle( h4Tag, currentStyleNum );
break;
}
case '5':
{
styleMap->setStyle( h5Tag, currentStyleNum );
break;
}
default:
break;
}
}
}
}