summaryrefslogtreecommitdiffstats
path: root/lib/kotext/KoTextFormatter.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kotext/KoTextFormatter.h
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kotext/KoTextFormatter.h')
-rw-r--r--lib/kotext/KoTextFormatter.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/lib/kotext/KoTextFormatter.h b/lib/kotext/KoTextFormatter.h
new file mode 100644
index 00000000..ad120437
--- /dev/null
+++ b/lib/kotext/KoTextFormatter.h
@@ -0,0 +1,114 @@
+/* This file is part of the KDE project
+ Copyright (C) 2001 David Faure <faure@kde.org>
+
+ 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 <faure@kde.org>
+ */
+class KOTEXT_EXPORT KoTextFormatter : public KoTextFormatterBase
+{
+public:
+ KoTextFormatter();
+ virtual ~KoTextFormatter();
+
+ virtual bool format( KoTextDocument *doc, KoTextParag *parag, int start, const QMap<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
+ QPair<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.
+ QPair<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