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
|
/* This file is part of the KDE project
Copyright (C) 2001 David Faure <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef kotextformatter_h
#define kotextformatter_h
#include "KoRichText.h"
class KoTextZoomHandler;
class KoHyphenator;
/**
* We implement our own text formatter to implement WYSIWYG:
* It is heavily based on KoTextFormatterBaseBreakWords, but stores the x position
* of characters (and their width) in pixels, whereas all the rest is in L.U.
* It also implements hyphenation.
* @author David Faure <[email protected]>
*/
class KOTEXT_EXPORT KoTextFormatter : public KoTextFormatterBase
{
public:
KoTextFormatter();
virtual ~KoTextFormatter();
virtual bool format( KoTextDocument *doc, KoTextParag *parag, int start, const TQMap<int, KoTextParagLineStart*> &oldLineStarts, int& y, int& widthUsed );
// Called after formatting a paragraph
virtual void postFormat( KoTextParag* parag );
KoHyphenator* hyphenator() {
return m_hyphenator;
}
private:
KoHyphenator* m_hyphenator;
};
// Internal class for KoTextFormatter, holds all the temporary data
// KoTextFormatter is basically the settings and the algorithm being used
// KoTextFormatterCore is where the formatting really happens
class KoTextFormatterCore
{
public:
KoTextFormatterCore( KoTextFormatter* settings, KoTextDocument *doc, KoTextParag *parag, int start );
bool format();
// widthUsed is the width of the wider line (with the current
// word-breaking, margins included, but e.g. centering not included).
// Unused in KWord currently, this is however used by KPresenter's
// "resize object to fit contents" feature.
int widthUsed() const { return wused; }
int resultY() const { return y; }
protected:
// Return ww (in LU) and pixelww (in pixels)
// Should be called only once per char
TQPair<int, int> determineCharWidth();
KoTextParagLineStart *koFormatLine(
KoTextZoomHandler *zh,
KoTextParag * /*parag*/, KoTextString *string, KoTextParagLineStart *line,
KoTextStringChar *startChar, KoTextStringChar *lastChar, int align, int space );
KoTextParagLineStart *koBidiReorderLine(
KoTextZoomHandler *zh,
KoTextParag * /*parag*/, KoTextString *text, KoTextParagLineStart *line,
KoTextStringChar *startChar, KoTextStringChar *lastChar, int align, int space );
void moveChar( KoTextStringChar& chr, KoTextZoomHandler *zh,
int deltaX, int deltaPixelX );
// Total left margin for a given line
// Takes into account parag's leftmargin, firstlinemargin and counter,
// but not adjustMargins (application hook)
int leftMargin( bool firstLine, bool includeFirstLineMargin = true ) const;
int rightMargin( bool firstLine ) const;
private:
KoTextFormatter* settings;
KoTextDocument* doc;
KoTextParag* parag;
int start; // always 0 currently
int wused; // see widthUsed
int y;
int availableWidth;
int maxY;
// When moving a big item down, we might want to rollback
// to the 'best position for it' if we can't make it fit anywhere else.
TQPair<int,int> maxAvailableWidth; // first=y second=available width
// Information on current char
KoTextStringChar *c;
int i; // index number (in the paragraph)
int x; // X position (in LU)
};
#endif
|