lib

KoTextFormatter.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 David Faure <faure@kde.org>
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef kotextformatter_h
21#define kotextformatter_h
22
23#include "KoRichText.h"
25class KoHyphenator;
26
34class KOTEXT_EXPORT KoTextFormatter : public KoTextFormatterBase
35{
36public:
37 KoTextFormatter();
38 virtual ~KoTextFormatter();
39
40 virtual bool format( KoTextDocument *doc, KoTextParag *parag, int start, const TQMap<int, KoTextParagLineStart*> &oldLineStarts, int& y, int& widthUsed );
41
42 // Called after formatting a paragraph
43 virtual void postFormat( KoTextParag* parag );
44
45 KoHyphenator* hyphenator() {
46 return m_hyphenator;
47 }
48private:
49 KoHyphenator* m_hyphenator;
50};
51
52// Internal class for KoTextFormatter, holds all the temporary data
53// KoTextFormatter is basically the settings and the algorithm being used
54// KoTextFormatterCore is where the formatting really happens
55class KoTextFormatterCore
56{
57public:
58 KoTextFormatterCore( KoTextFormatter* settings, KoTextDocument *doc, KoTextParag *parag, int start );
59
60 bool format();
61
62 // widthUsed is the width of the wider line (with the current
63 // word-breaking, margins included, but e.g. centering not included).
64 // Unused in KWord currently, this is however used by KPresenter's
65 // "resize object to fit contents" feature.
66 int widthUsed() const { return wused; }
67 int resultY() const { return y; }
68
69protected:
70 // Return ww (in LU) and pixelww (in pixels)
71 // Should be called only once per char
72 TQPair<int, int> determineCharWidth();
73
74 KoTextParagLineStart *koFormatLine(
75 KoTextZoomHandler *zh,
76 KoTextParag * /*parag*/, KoTextString *string, KoTextParagLineStart *line,
77 KoTextStringChar *startChar, KoTextStringChar *lastChar, int align, int space );
78
79 KoTextParagLineStart *koBidiReorderLine(
80 KoTextZoomHandler *zh,
81 KoTextParag * /*parag*/, KoTextString *text, KoTextParagLineStart *line,
82 KoTextStringChar *startChar, KoTextStringChar *lastChar, int align, int space );
83
84 void moveChar( KoTextStringChar& chr, KoTextZoomHandler *zh,
85 int deltaX, int deltaPixelX );
86
87 // Total left margin for a given line
88 // Takes into account parag's leftmargin, firstlinemargin and counter,
89 // but not adjustMargins (application hook)
90 int leftMargin( bool firstLine, bool includeFirstLineMargin = true ) const;
91 int rightMargin( bool firstLine ) const;
92
93
94private:
95 KoTextFormatter* settings;
96 KoTextDocument* doc;
97 KoTextParag* parag;
98 int start; // always 0 currently
99 int wused; // see widthUsed
100 int y;
101 int availableWidth;
102 int maxY;
103
104 // When moving a big item down, we might want to rollback
105 // to the 'best position for it' if we can't make it fit anywhere else.
106 TQPair<int,int> maxAvailableWidth; // first=y second=available width
107
108 // Information on current char
109 KoTextStringChar *c;
110 int i; // index number (in the paragraph)
111 int x; // X position (in LU)
112};
113
114#endif
The KoHyphenator class provides an interface to the libhnj hyphenation library.
Definition kohyphen.h:56
We implement our own text formatter to implement WYSIWYG: It is heavily based on KoTextFormatterBaseB...
This class extends KoZoomHandler to add support for WYSIWYG text layouting.