summaryrefslogtreecommitdiffstats
path: root/filters/kword/pdf/fstring.h
blob: 644c9398d9ec645208957170d47727643ab8fbcf (plain)
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
/*
 * Copyright (c) 2002-2003 Nicolas HADACEK (hadacek@kde.org)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program 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 General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef FSTRING_H
#define FSTRING_H

#include "TextOutputDev.h"

#include <tqvaluevector.h>

#include "misc.h"


namespace PDFImport
{

class Data;

//-----------------------------------------------------------------------------
class Tabulator
{
public:
    enum Alignment { Left = 0, Center, Right, Character };
    enum Filling { Blank = 0, Dots, Line, Dash, DashDot, DashDotDot };

    Tabulator() : alignment(Left) {}

    TQDomElement createElement(Data &data) const;

public:
    double    pos;
    Alignment alignment;
    Filling   filling;
    TQChar     alignmentChar;
};

inline bool operator <(const Tabulator &t1, const Tabulator &t2)
{ return t1.pos<t2.pos; }

//-----------------------------------------------------------------------------
class Block
{
public:
    Block() : link(0) {}

public:
    Font        font;
    const Link *link;
    TQString     text;
};

//-----------------------------------------------------------------------------
enum Align { AlignLeft, AlignRight, AlignCenter, AlignBlock };

class Paragraph
{
public:
    Paragraph();
    Paragraph(TextLine *first, uint nbLines);

    const DRect &rect() const { return _rect; }

    bool hasOneLine() const { return _lines.count()==1; }
    const TQValueList<TextLine *> lines() const { return _lines; }
    bool isFirst(const TextLine *line) const { return line==_lines.first();}
    bool isSecond(const TextLine* line) const
        { return (_lines.count()>1 && line==_lines.first()->next); }
    bool isLast(const TextLine *line) const { return line==_lines.last(); }

    int findTab(double xMin, const TextLine *) const;
    uint findNbTabs(uint i, double prevXMax) const;
    int charFromEnd(uint dec, uint &blockIndex) const;

public:
    ParagraphType type;
    uint          frameIndex;
    double        firstIndent, leftIndent, offset;
    Align         align;
    TQValueVector<Tabulator> tabs;
    TQValueList<Block>       blocks;

private:
    TQValueList<TextLine *> _lines;
    DRect                  _rect;
};

//-----------------------------------------------------------------------------
class String : public TextString
{
public:
    String(GfxState *state, double x0, double y0,
           double fontSize, uint frameIndex);

    uint frameIndex() const { return _frameIndex; }
    const Font &font() const { return _font; }
    DRect rect() const { return DRect(xMin, xMax, yMin, yMax); }
    bool checkCombination(TextString *s);

public:
    const Link *link;

private:
    void addChar(GfxState *state, double x, double y,
                 double dx, double dy, Unicode u);

private:
    Font _font;
    uint _frameIndex;
};

} // namespace

#endif