• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

fp_Line.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 1998,1999 AbiSource, Inc.
00003  * Copyright (c) 2001,2002 Tomas Frydrych
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 #ifndef FP_LINE_H
00022 #define FP_LINE_H
00023 
00024 #ifdef FMT_TEST
00025 #include <stdio.h>
00026 #endif
00027 
00028 #include "ut_misc.h"
00029 #include "ut_types.h"
00030 #include "ut_vector.h"
00031 #include "pt_Types.h"
00032 #include "fl_BlockLayout.h"
00033 #include "fp_Column.h"
00034 #include "fp_ContainerObject.h"
00035 //#include "fmt_Types.h"
00036 
00037 class fp_Run;
00038 class GR_Graphics;
00039 class fp_Container;
00040 class fp_VerticalContainer;
00041 
00042 struct dg_DrawArgs;
00043 
00044 // ----------------------------------------------------------------
00045 /*
00046     fp_Line represents a single line.  A fp_Line is a collection of
00047     Runs.
00048 */
00049 //these are the initial sizes of the temp buffers
00050 #define TEMP_LINE_BUFFER_SIZE 512
00051 
00052 // the memory requirement connected with the following constant
00053 // is 9 bytes per 1; 100 is reasonable: if loading documents with long paragraphs
00054 // this will have to be reallocated, since initially each paragraph is loaded
00055 // on a single line, but for creating documents from a scratch this is
00056 // more than adequate.
00057 #define RUNS_MAP_SIZE 100
00058 /* the following define determines whether the map used to convert logical to visual position and
00059    vice versa is shared by all lines, or whether each line has map of its own. In the former case
00060    only small encrease in memory requirenments is needed, but we have to recalculate the map
00061    more often; in the latter case we only need to recalculate the map when a run
00062    is added or deleted, but the increase in memory requirenments is significant:
00063    sizeof(UT_uint32) * run_count * no_of_lines
00064 
00065    there is a mechanism in place that makes sure that the static map gets calculated only when it
00066    is really necessary and from my debugging experience this is not much more often that in the
00067    case of the non-static map, so this appears to be definitely the better option;
00068    PLEASE NOTE that if you change the option you will have to rebuild.
00069 */
00070 #define USE_STATIC_MAP
00071 
00072 enum FL_WORKING_DIRECTION {WORK_FORWARD = 1,WORK_BACKWARD = -1,WORK_CENTER = 0};
00073 enum FL_WHICH_TABSTOP {USE_PREV_TABSTOP,USE_NEXT_TABSTOP,USE_FIXED_TABWIDTH};
00074 
00075 
00076 
00077 class ABI_EXPORT fp_Line : public fp_Container
00078 {
00079     friend class fp_Run; // this is to allow access to
00080                          // _createMapOfRuns() which I do not want to
00081                          // make public
00082 public:
00083     fp_Line(fl_SectionLayout * pSectionLayout);
00084     ~fp_Line();
00085 
00086     fl_BlockLayout*     getBlock(void) const        { return m_pBlock; }
00088     virtual UT_sint32   getHeight(void) const;
00089 
00090     virtual UT_sint32   getX(void) const;
00091     virtual UT_sint32   getY(void) const;
00092 
00093     UT_sint32       getMaxWidth(void) const ;
00094     UT_sint32       getAscent(void) const;
00095     UT_sint32       getDescent(void) const;
00096     UT_sint32               getNumRunsInLine(void) const {return m_vecRuns.getItemCount();}
00097     UT_sint32       getColumnGap(void) const;
00098     void                        setAssignedScreenHeight(UT_sint32);
00099     bool                        assertLineListIntegrity(void);
00100     void                        setMaxWidth(UT_sint32);
00101     virtual void                setX(UT_sint32 i, bool bDontClearIfNeeded = false);
00102     virtual void                setY(UT_sint32);
00103 
00104     virtual void                setContainer(fp_Container*);
00105     void                setBlock(fl_BlockLayout * pBlock);
00106 
00107     fp_Container *              getColumn(void) const;
00108     fp_Page *                   getPage(void) const;
00109 
00110     virtual void        setWidth(UT_sint32 ){}
00111     virtual void        setHeight(UT_sint32 i);
00112     virtual UT_sint32   getWidth(void) const { return m_iWidth;}
00113     virtual UT_sint32   getDrawingWidth(void) const;
00114     UT_sint32           getWidthToRun(fp_Run * pLastRun);
00115     UT_sint32           getFilledWidth(void) const;
00116     virtual bool        isVBreakable(void) { return false;}
00117     virtual bool        isHBreakable(void) {return true;}
00118     virtual UT_sint32   wantVBreakAt(UT_sint32) { return 0;}
00119     virtual UT_sint32   wantHBreakAt(UT_sint32) { return 0;}
00120     virtual fp_ContainerObject * VBreakAt(UT_sint32) { return NULL;}
00121     virtual fp_ContainerObject * HBreakAt(UT_sint32) {return NULL;}
00122     virtual UT_uint32 distanceFromPoint(UT_sint32, UT_sint32) {return 0;}
00123     virtual fp_Container*   getNextContainerInSection(void) const;
00124     virtual fp_Container*   getPrevContainerInSection(void) const;
00125     fp_Run *    getRunFromIndex( UT_uint32 runIndex);
00126     bool        containsForcedColumnBreak(void) const;
00127     bool        containsForcedPageBreak(void) const;
00128     bool        containsFootnoteReference(void);
00129     bool        getFootnoteContainers(UT_GenericVector<fp_FootnoteContainer *>* pvecFoots);
00130     bool        containsAnnotations(void);
00131     bool        getAnnotationContainers(UT_GenericVector<fp_AnnotationContainer *>* pvecAnnotations);
00132     void        addRun(fp_Run*);
00133     void        insertRunAfter(fp_Run* pRun1, fp_Run* pRun2);
00134     void        insertRunBefore(fp_Run* pNewRun, fp_Run* pBefore);
00135     void        insertRun(fp_Run*);
00136     bool     removeRun(fp_Run*, bool bTellTheRunAboutIt=true);
00137 
00138     inline  bool        isEmpty(void) const             { return ((m_vecRuns.getItemCount()) == 0); }
00139     inline  int         countRuns(void) const           { return m_vecRuns.getItemCount(); }
00140     inline  fp_Run*     getFirstRun(void) const         { if(countRuns() > 0)  return ((fp_Run*) m_vecRuns.getFirstItem()); else return NULL; }
00141     fp_Run*     getLastRun(void) const ;
00142     fp_Run*     getLastTextRun(void) const ;
00143 
00144     fp_Run* calculateWidthOfRun(UT_sint32 &iX,
00145                     UT_uint32 iIndxVisual,
00146                     FL_WORKING_DIRECTION eWorkingDirection,
00147                     FL_WHICH_TABSTOP eUseTabStop);
00148 
00149     void        getWorkingDirectionAndTabstops(FL_WORKING_DIRECTION &eWorkingDirection, FL_WHICH_TABSTOP &eUseTabStop) const;
00150 
00151     inline  bool    isFirstLineInBlock(void) const;
00152     bool    isLastLineInBlock(void) const;
00153 
00154     virtual UT_Option<UT_Rect>   getScreenRect() const;
00155     virtual void            markDirtyOverlappingRuns(const UT_Rect& recScreen);
00156 
00157     void        remove(void);
00158     UT_sint32   getMarginBefore(void) const;
00159     UT_sint32   getMarginAfter(void) const;
00160     virtual void        mapXYToPosition(UT_sint32 xPos, UT_sint32 yPos, PT_DocPosition& pos, bool& bBOL, bool& bEOL, bool& isTOC);
00161     void        getOffsets(const fp_Run* pRun, UT_sint32& xoff, UT_sint32& yoff) const;
00162     void        getScreenOffsets(const fp_Run* pRun, UT_sint32& xoff, UT_sint32& yoff) const;
00163     virtual void  clearScreen(void);
00164     void        clearScreenFromRunToEnd(UT_uint32 runIndex);
00165     void        clearScreenFromRunToEnd(fp_Run * pRun);
00166     bool        containsOffset(PT_DocPosition blockOffset);
00167     void         setScreenCleared(bool bisCleared)
00168         {   m_bIsCleared = bisCleared;}
00169     bool         isScreenCleared(void) const { return m_bIsCleared;}
00170     void         setAdditionalMargin(UT_sint32 iAccum)
00171       { m_iAdditionalMarginAfter = iAccum;}
00172     virtual void        draw(dg_DrawArgs*);
00173     virtual void        draw(GR_Graphics*);
00174     void        align(void);
00175     void        layout(void);
00176     bool        recalculateFields(UT_uint32 iUpdateCount);
00177     void        recalcHeight(fp_Run * pLast = NULL);
00178     void        recalcMaxWidth(bool bDontClearIfNeeded = false);
00179     void            setReformat(void);
00180     void        coalesceRuns(void);
00181 
00182     UT_sint32   calculateWidthOfLine(void);
00183     UT_sint32   calculateWidthOfTrailingSpaces(void);
00184     void        resetJustification(bool bPermanent);
00185     void        justify(UT_sint32 iAmount);
00186     UT_uint32   countJustificationPoints(void);
00187 
00188     bool        isLastCharacter(UT_UCSChar Character) const;
00189 
00190     bool        findNextTabStop(UT_sint32 iStartX, UT_sint32& iPosition, eTabType& iType, eTabLeader& iLeader );
00191     bool        findPrevTabStop(UT_sint32 iStartX, UT_sint32& iPosition, eTabType& iType, eTabLeader& iLeader );
00192     void        setNeedsRedraw(void);
00193     //void      setRedoLayout(void){ m_bRedoLayout = true; }
00194     bool        needsRedraw(void) { return m_bNeedsRedraw; }
00195     bool        redrawUpdate(void);
00196     fp_Run *    getLastVisRun();
00197     fp_Run *    getFirstVisRun();
00198     UT_uint32   getVisIndx(fp_Run* pRun);
00199     fp_Run *    getRunAtVisPos(UT_sint32 i);
00200     void        setMapOfRunsDirty(){m_bMapDirty = true;};
00201     void        addDirectionUsed(UT_BidiCharType dir, bool bRefreshMap = true);
00202     void        removeDirectionUsed(UT_BidiCharType dir, bool bRefreshMap = true);
00203     void        changeDirectionUsed(UT_BidiCharType oldDir, UT_BidiCharType newDir, bool bRefreshMap = true);
00204     UT_sint32   getBreakTick(void) const
00205         { return  m_iBreakTick;}
00206     void        setBreakTick(UT_sint32 iTick)
00207         { m_iBreakTick = iTick;}
00208     void        setWrapped(bool bWrapped)
00209         { m_bIsWrapped = bWrapped;}
00210     bool        isWrapped(void) const
00211         { return m_bIsWrapped;}
00212     void        setSameYAsPrevious(bool bSameAsPrevious);
00213     bool        isSameYAsPrevious(void) const
00214         { return m_bIsSameYAsPrevious;}
00215     void        setAlongTopBorder(bool bAlongTopBorder)
00216         { m_bIsAlongTopBorder = bAlongTopBorder;}
00217     void        setAlongBotBorder(bool bAlongBotBorder)
00218         { m_bIsAlongBotBorder = bAlongBotBorder;}
00219     bool        isAlongTopBorder(void) const
00220         { return m_bIsAlongTopBorder;}
00221     bool        isAlongBotBorder(void) const
00222         { return m_bIsAlongBotBorder;}
00223     void        genOverlapRects(UT_Rect & recLeft, UT_Rect & recRight);
00224 
00225     bool        canContainPoint() const;
00226     UT_sint32   calcLeftBorderThick(void);
00227     UT_sint32   calcRightBorderThick(void);
00228     UT_sint32   calcTopBorderThick(void);
00229     UT_sint32   calcBotBorderThick(void);
00230     void        calcBorderThickness(void);
00231     UT_sint32   getLeftThick(void) const;
00232     UT_sint32   getRightThick(void) const;
00233     UT_sint32   getTopThick(void) const;
00234     UT_sint32   getBotThick(void) const;
00235     UT_sint32   getAvailableWidth(void) const;
00236     const fp_Line *   getFirstInContainer(void) const;
00237     const fp_Line *   getLastInContainer(void) const;
00238     bool        canDrawTopBorder(void) const;
00239     bool        canDrawBotBorder(void) const;
00240     void        drawBorders(GR_Graphics * pG);
00241     UT_sint32              getLeftEdge(void) const;
00242     UT_sint32              getRightEdge(void) const;
00243     bool        getAbsLeftRight(UT_sint32& left ,UT_sint32& right); // FIXME try to make it const
00244     bool        hasBordersOrShading(void) const;
00245 #ifdef FMT_TEST
00246     void        __dump(FILE * fp) const;
00247 #endif
00248 
00249 protected:
00250     void    _calculateWidthOfRun(UT_sint32 &iX,
00251                                  fp_Run * pRun,
00252                                  UT_uint32 iIndx,
00253                                  UT_uint32 iCountRuns,
00254                                  FL_WORKING_DIRECTION eWorkingDirection,
00255                                  FL_WHICH_TABSTOP eUseTabStop,
00256                                  UT_BidiCharType iDomDirection
00257                                  );
00258 
00259 private:
00260     void        _splitRunsAtSpaces(void);
00261     void        _doClearScreenFromRunToEnd(UT_sint32 runIndex);
00262 
00263 
00264     void        setAscent(UT_sint32 i) { m_iAscent = i; }
00265     void        setDescent(UT_sint32 i) { m_iDescent = i; }
00266     void        setScreenHeight(UT_sint32 i) {m_iScreenHeight =i;}
00267 
00268 
00269     fl_BlockLayout* m_pBlock;
00270     fp_Container*   m_pContainer;
00271 
00272     UT_sint32       m_iWidth;
00273     UT_sint32       m_iMaxWidth;
00274     UT_sint32       m_iClearToPos;
00275     UT_sint32       m_iClearLeftOffset;
00276     UT_sint32       m_iHeight;
00279     UT_sint32       m_iScreenHeight;
00280     UT_sint32       m_iAscent;
00281     UT_sint32       m_iDescent;
00282 
00283     UT_sint32       m_iX;
00284     UT_sint32       m_iY;
00285     UT_GenericVector<fp_Run *>  m_vecRuns;
00286 
00287     bool            m_bNeedsRedraw;
00288     //bool          m_bRedoLayout;
00289     static UT_sint32 * s_pOldXs;
00290     static UT_uint32   s_iOldXsSize;
00291     static UT_uint32   s_iClassInstanceCounter;
00292 
00293     UT_uint32       _getRunVisIndx(UT_sint32 indx);
00294     UT_uint32       _getRunLogIndx(UT_sint32 indx);
00295     UT_sint32       _createMapOfRuns();
00296 #ifdef USE_STATIC_MAP
00297     static UT_Byte     * s_pEmbeddingLevels;
00298     static UT_uint32   * s_pMapOfRunsL2V;
00299     static UT_uint32   * s_pMapOfRunsV2L;
00300     static UT_UCS4Char * s_pPseudoString;
00301 
00302 
00303     static UT_sint32   s_iMapOfRunsSize;
00304     static fp_Line   * s_pMapOwner;
00305     bool            m_bMapDirty;
00306 #else
00307     UT_sint32  *    m_pMapOfDirs;
00308     UT_sint32  *    m_pMapOfRunsL2V;
00309     UT_sint32  *    m_pMapOfRunsV2L;
00310 
00311     UT_sint32       m_iMapOfRunsSize;
00312 #endif
00313     UT_uint32       m_iRunsRTLcount;
00314     UT_uint32       m_iRunsLTRcount;
00315     UT_sint32       m_iMaxDirLevel;
00316     bool            m_bIsCleared;
00317     bool            m_bContainsFootnoteRef; // updated when runs added/removed.
00318     void            _updateContainsFootnoteRef(void);
00319     UT_sint32       m_iBreakTick;
00320     bool            m_bIsWrapped;
00321     bool            m_bIsSameYAsPrevious;
00322     bool            m_bIsAlongTopBorder;
00323     bool            m_bIsAlongBotBorder;
00324         UT_sint32       m_iAdditionalMarginAfter;
00325     UT_sint32       m_iLeftThick;
00326     UT_sint32       m_iRightThick;
00327     UT_sint32       m_iTopThick;
00328     UT_sint32       m_iBotThick;
00329 };
00330 
00331 #endif /* FP_LINE_H */
00332 
00333 

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1