Back to index

scribus-ng  1.3.4.dfsg+svn20071115
storytext.h
Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 /***************************************************************************
00008 pageitem.cpp  -  description
00009 -------------------
00010     begin                : Sat Apr 7 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013        ***************************************************************************/
00014 
00015 /***************************************************************************
00016 *                                                                         *
00017 *   This program is free software; you can redistribute it and/or modify  *
00018 *   it under the terms of the GNU General Public License as published by  *
00019 *   the Free Software Foundation; either version 2 of the License, or     *
00020 *   (at your option) any later version.                                   *
00021 *                                                                         *
00022 ***************************************************************************/
00023 
00024 
00025 #ifndef STORYTEXT_H_
00026 #define STORYTEXT_H_
00027 
00028 #include <qobject.h>
00029 #include <qstring.h>
00030 #include <qvaluevector.h>
00031 #include <qptrvector.h>
00032 #include <qptrlist.h>
00033 #include <cassert>
00034 
00035 //#include "text/paragraphlayout.h"
00036 #include "text/frect.h"
00037 #include "text/specialchars.h"
00038 #include "sctextstruct.h"
00039 #include "style.h"
00040 #include "styles/charstyle.h"
00041 #include "styles/paragraphstyle.h"
00042 #include "desaxe/saxio.h"
00043 
00044 #ifdef NLS_CONFORMANCE
00045 #define NLS_PRIVATE private
00046 #else
00047 #define NLS_PRIVATE public
00048 #endif
00049 
00050 class CharStyle;
00051 class ParagraphStyle;
00052 class PageItem;
00053 //class ScTextEngine;
00054 //class ScScriptItem;
00055 class ScribusDoc;
00056 class ScText_Shared;
00057 class ResourceCollection;
00058  
00059 
00060 struct LineSpec 
00061 {
00062        double x;
00063        double y;
00064        double width;
00065        double ascent;
00066        double descent;
00067        
00068        int firstItem;
00069        int lastItem;
00070        double naturalWidth;
00071 };
00072 
00089 class SCRIBUS_API StoryText : public QObject, public SaxIO
00090 {
00091        Q_OBJECT
00092        
00093  public:
00094        StoryText(ScribusDoc * doc);
00095        StoryText();
00096        StoryText(const StoryText & other);
00097        StoryText& operator= (const StoryText & other);
00098        virtual ~StoryText();
00099        
00100        static const Xml_string saxxDefaultElem;
00101        static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
00102        
00103        virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00104        virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
00105        
00106        void clear();
00107        StoryText copy() const;
00108        void insert(int pos, const StoryText& other, bool onlySelection = false);
00109        void append(const StoryText& other) { insert(length(), other, false); }
00110        void removeChars(int pos, uint len);
00111        void insertChars(int pos, QString txt, bool applyNeighbourStyle = false);
00112        void insertObject(int pos, PageItem* obj);
00113        void replaceChar(int pos, QChar ch);
00114 
00115        void hyphenateWord(int pos, uint len, char* hyphens);
00116        
00117        int length() const;
00118        QChar text(int pos) const;
00119        QString text(int pos, uint len) const;
00120        PageItem* object(int pos) const;
00121        
00122        int nextCharPos(int c);
00123        int prevCharPos(int c);
00124        int nextWordPos(int c);
00125        int prevWordPos(int c);
00126        int nextLinePos(int c, double oldX);
00127        int prevLinePos(int c, double oldX);
00128        int nextFramePos(int c);
00129        int prevFramePos(int c);
00130        
00131        const CharStyle& charStyle(int pos) const;
00132        const ParagraphStyle& paragraphStyle(int pos) const;
00133        const ParagraphStyle& defaultStyle() const;
00134        void setDefaultStyle(const ParagraphStyle& style);
00135        void setCharStyle(int pos, uint len, const CharStyle& style);
00136        void setStyle(int pos, const ParagraphStyle& style);
00137        void applyCharStyle(int pos, uint len, const CharStyle& style);
00138        void applyStyle(int pos, const ParagraphStyle& style);
00139        void eraseCharStyle(int pos, uint len, const CharStyle& style);
00140        void eraseStyle(int pos, const ParagraphStyle& style);
00141        void replaceStyles(QMap<QString,QString> newNameForOld);
00142        void replaceCharStyles(QMap<QString,QString> newNameForOld);
00143        
00144        void getNamedResources(ResourceCollection& lists) const;
00145        void replaceNamedResources(ResourceCollection& newNames);
00146        
00147        uint nrOfParagraphs() const;
00148        int startOfParagraph(uint index) const;
00149        int endOfParagraph(uint index) const;
00150 
00151        uint nrOfRuns() const;
00152        int startOfRun(uint index) const;
00153        int endOfRun(uint index) const;
00154 
00155 // positioning
00156        int nextChar(int pos);
00157        int prevChar(int pos);
00158        int nextWord(int pos);
00159        int prevWord(int pos);
00160        int nextSentence(int pos);
00161        int prevSentence(int pos);
00162        int nextParagraph(int pos);
00163        int prevParagraph(int pos);
00164 
00165 // these need valid layout:
00166 
00167        int startOfLine(int pos);
00168        int endOfLine(int pos);
00169        int prevLine(int pos);
00170        int nextLine(int pos);
00171        int startOfFrame(int pos);
00172        int endOfFrame(int pos);
00173 
00174 // selection
00175 
00176        void selectAll();
00177        void deselectAll();
00178        void removeSelection();
00179        void select(int pos, uint len, bool on = true);
00180        bool selected(int pos) const;
00181        int startOfSelection() const;
00182        int endOfSelection() const;
00183        int lengthOfSelection() const;
00184 
00185 
00186 //  when physical view doesn't match logical view any more:
00187 
00189        void invalidateObject(const PageItem* embedded);
00191        void invalidateLayout();
00192 
00193 public slots:
00195        void invalidateAll();
00196 
00197 
00198 
00199 public:
00200 // physical view
00201 
00202        bool overflows() const;
00204        int layout(int startItem);
00205        uint nrOfItems() const;
00206 //private:
00207        ScText * item(uint index);
00208        const ScText * item(uint index) const;
00209 public:
00210        ScText * item_p(uint index) { return item(index); }
00211 //     void bidiReorder(uint firstItem, uint lastItem, uint indices[]) const;
00213        const QString itemText(uint index) const;
00215        const CharStyle itemStyle(uint index) const;
00217        int startOfItem(uint index) const;
00219        int endOfItem(uint index) const;
00220 //     const ScTextEngine * engineForRun(uint index) const;
00221 //     const ScTextEngine * engineForItem(uint index) const;
00222 
00223 //     ParagraphLayout layouter;
00224 
00225        int screenToPosition(FPoint coord) const;
00226        FRect  boundingBox(int pos, uint len = 1) const;
00227 
00228        uint lines() const { return (uint) m_lines.count(); }
00229        
00230        LineSpec line(uint i) const { return m_lines[i]; }
00231        
00232        void appendLine(const LineSpec& ls) 
00233        { 
00234               assert( ls.firstItem >= 0 );
00235               assert( ls.firstItem < length() );
00236               assert( ls.lastItem >= 0 && ls.firstItem - ls.lastItem < 1 );
00237               assert( ls.lastItem < length() );
00238               m_lines.append(ls);
00239               if (lastFrameItem < firstFrameItem) {
00240                      firstFrameItem = ls.firstItem;
00241                      lastFrameItem = ls.lastItem;
00242               }
00243               else {
00244                      firstFrameItem = QMIN(firstFrameItem, ls.firstItem);
00245                      lastFrameItem = QMAX(lastFrameItem, ls.lastItem);
00246               }
00247        }
00248        
00249        void clearLines() 
00250        { 
00251               m_lines.clear(); 
00252               firstFrameItem = 0; 
00253               lastFrameItem = -1; 
00254        }
00255        
00256        int firstInFrame() { return firstFrameItem; }
00257        int lastInFrame() { return lastFrameItem; }
00258 
00259 private:
00260        ScribusDoc * doc; 
00261        int selFirst, selLast;
00262        int firstFrameItem, lastFrameItem;
00263        QValueVector<LineSpec> m_lines;
00264        bool m_validLayout;
00265        double m_magicX;
00266        int m_lastMagicPos;
00267        
00269        void invalidate(int firstRun, int lastRun);
00270        void removeParSep(int pos);
00271        void insertParSep(int pos);
00272 
00273        //     int splitRun(int pos);
00274        
00278 //     void validate();
00280        ScText_Shared * d;
00282 //     uint layouterVersion;
00284 //     bool layouterValid;
00285  };
00286 
00287 
00288 #endif /*STORYTEXT_H_*/