-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfootnotedestination.cpp
100 lines (89 loc) · 2.18 KB
/
footnotedestination.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
/*Copyright 2001
*
* footnotedestination.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)
*/
// footnotedestination.cpp: implementation of the FootnoteDestination class.
//
//////////////////////////////////////////////////////////////////////
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#include "token.h"
#include "charoutput.h"
#include "charsource.h"
#include "tokeniser.h"
#include "destination.h"
#include "footnotedestination.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FootnoteDest::FootnoteDest()
{
}
FootnoteDest::~FootnoteDest()
{
}
bool FootnoteDest::handleToken(Token *token)
{
switch (token->getType()) {
case groupToken:
{
GroupToken *g = (GroupToken *)token;
if ( g->group == startGroup ) {
groupLevel++;
} else {
groupLevel--;
}
if (groupLevel <0) {
char fnString[64];
groupLevel = 0; // reinitialise this object
footnotes.push_back( current );
sprintf( fnString,
"<sup><a href=\"#footnote_%d\">%d</a></sup>", footnotes.size(), footnotes.size() );
out->putString( fnString );
current = "";
// ready for reusing on another footnote!
return true;
}
}
break;
case controlToken:
// ignore all formatting in footnotes
break;
case charToken:
current += token->text;
break;
default:
break;
}
return false;
}
FootnoteDest::FootnoteDest(CharOutput *out)
{
this->out= out;
}
void FootnoteDest::outputAll()
{
char fnString[96];
out->putString ( "<hr>" );
for ( int i = 0; i < footnotes.size() ; i++ ) {
sprintf( fnString,
"<p><sup>%d</sup> ", i++);
out->putString( fnString );
out->putString( footnotes[i] );
out->putString( "</p>" );
}
}