nodetxtl.h

Go to the documentation of this file.
00001 // $Id: nodetxtl.h 1535 2006-07-25 16:50:32Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // The TextLine object
00099 
00100 #ifndef INC_NODETXTL
00101 #define INC_NODETXTL
00102 
00103 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "nodetxts.h"
00106 //#include "attrmgr.h"  // for FormatRegion::GetTracking() - in camtypes.h [AUTOMATICALLY REMOVED]
00107 
00108 class EOLNode;
00109 class CharMetrics;
00110 class NodeGroup;
00111 class BecomeA;
00112 
00113 /********************************************************************************************
00114 >   class FormatRegion: public RenderRegion
00115 
00116     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00117     Created:    17/03/95
00118     Purpose:    A FormatRegion is a render region that is used during the formatting of
00119                 characters.  No actual rendering is done; the FormatRegion provides a simple
00120                 way of managing the attribute stack.
00121 
00122                 Call the init function before using the FormatRegion.  This is passed the 
00123                 root node of the subtree to format.  The Init function renders all the attributes
00124                 applied to this node into the FormatRegion.  You can then use the object
00125                 as an attribute stack.  You will want to call each nodes Format function.
00126                 NOTE: you will also want to render all attributes you come across into the
00127                 FormatRegion
00128 ********************************************************************************************/
00129 
00130 class FormatRegion : public RenderRegion
00131 {
00132     CC_DECLARE_DYNAMIC(FormatRegion)
00133 
00134     FormatRegion();
00135     ~FormatRegion();                                           
00136 
00137     BOOL Init(NodeRenderableInk* pFirstNode);
00138 
00139     // To be safe we override all drawing functions to to prevent drawing
00140     // Some are pure and have to be overridden
00141     // Pure drawing functions
00142     virtual void DrawPathToOutputDevice(Path *PathToRender, PathShape shapePath=PATHSHAPE_PATH) {ERROR3("Rendering into a FormatRegion");};
00143     virtual void DrawRect(DocRect *RectToRender) {ERROR3("Rendering into a FormatRegion");};
00144     virtual void DrawDragRect(DocRect *RectToRender) {ERROR3("Rendering into a FormatRegion");};
00145     virtual void DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint) {ERROR3("Rendering into a FormatRegion");};
00146     virtual void DrawPixel(const DocCoord &Point) {ERROR3("Rendering into a FormatRegion");};
00147     virtual void DrawBlob(DocCoord p, BlobType type) {ERROR3("Rendering into a FormatRegion");};
00148     virtual void DrawCross(const DocCoord &Point, const UINT32 Size) {ERROR3("Rendering into a FormatRegion");};
00149     virtual void DrawBitmap(const DocCoord &Point, KernelBitmap* pBitmap) {ERROR3("Rendering into a FormatRegion");};
00150     virtual void DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID = NULL) {ERROR3("Rendering into a FormatRegion");};
00151     virtual void DrawBitmapBlob(const DocCoord &Point, KernelBitmap* BlobShape) {ERROR3("Rendering into a FormatRegion");};
00152     virtual void DrawBitmapBlob(const DocCoord &Point, ResourceID resID ) {ERROR3("Rendering into a FormatRegion");};
00153 
00154     // Non pure ones
00155     virtual void DrawFixedSystemText(StringBase *TheText, DocRect &BoundsRect, UINT32 uFormat = DEFAULT_TEXT_FORMATTING) {ERROR3("Rendering into a FormatRegion");};
00156     virtual void SetFixedSystemTextColours(DocColour *TextCol, DocColour *Background) {ERROR3("Rendering into a FormatRegion");};
00157     virtual void GetFixedSystemTextSize(StringBase *TheText, DocRect *BoundsRect, double* atDpi = NULL) {ERROR3("Rendering into a FormatRegion");};
00158     virtual void DrawPixelRect(DocRect *RectToRender) {ERROR3("Rendering into a FormatRegion");};
00159     virtual void DrawPixelLine(const DocCoord &StartPoint, const DocCoord &EndPoint) {ERROR3("Rendering into a FormatRegion");};
00160 
00161     // More pure functions
00162     virtual BOOL StopRender(void) {return TRUE;};
00163     virtual void InitClipping(void) {};
00164     virtual void InitAttributes(void) {};
00165     virtual void SetLineAttributes(void) {};
00166     virtual void SetOSDrawingMode(void) {};
00167     virtual void SetQualityLevel(void) {};
00168     virtual INT32 CalcPixelWidth(void) {return 1;};
00169     virtual INT32 CalcScaledPixelWidth(void) {return 1;};
00170 
00171 public:
00172     BOOL        GetCharMetrics(CharMetrics* pCharMetrics, WCHAR ch);
00173     MILLIPOINT  GetCharsKerning(WCHAR chLeft, WCHAR chRight);       // jwp 15/10/2000
00174 
00175     MILLIPOINT    GetTracking()      { return RR_TXTTRACKING(); }
00176     Justification GetJustification() { return RR_TXTJUSTIFICATION(); }
00177     MILLIPOINT    GetLineSpacing()   { return RR_TXTLINESPACE(); }
00178     FIXED16       GetLineSpaceRatio(){ return ((TxtLineSpaceAttribute*)CurrentAttrs[ATTR_TXTLINESPACE].pAttr)->Ratio; }
00179     MILLIPOINT    GetFontSize()      { return RR_TXTFONTSIZE(); }
00180     MILLIPOINT    GetBaseLineShift() { return RR_TXTBASELINE(); }
00181     MILLIPOINT    GetLeftMargin()    { return RR_TXTLEFTMARGIN(); }
00182     MILLIPOINT    GetRightMargin()   { return RR_TXTRIGHTMARGIN(); }
00183     MILLIPOINT    GetFirstIndent()   { return RR_TXTFIRSTINDENT(); }
00184     TxtRuler*     GetRuler()         { return RR_TXTRULER(); }
00185 private:
00186     std::auto_ptr<wxDC> m_pFormatDC;
00187 };
00188 
00189 
00190 /********************************************************************************************
00191 >   class FormatState: public CC_CLASS_MEMDUMP
00192 
00193     Author:     Martin Wuerthner <xara@mw-software.com>
00194     Created:    21/06/06
00195     Purpose:    encapsulates state when wrapping/formatting a text line
00196 ********************************************************************************************/
00197 
00198 class FormatState: public CC_CLASS_MEMDUMP
00199 {
00200  public:
00201     const BOOL       SetCharPositions;   // flag indicating whether formatting should set char positions
00202     const MILLIPOINT FitWidth;           // overall width available
00203     VisibleTextNode* const pFirstVTN;    // the first VTN in the line
00204     const MILLIPOINT CharPosOffset;      // used for formatting only (i.e., if SetCharPositions = TRUE)
00205     const MILLIPOINT ExtraOnChars;       // used for formatting only (i.e., if SetCharPositions = TRUE)
00206     const MILLIPOINT ExtraOnSpaces;      // used for formatting only (i.e., if SetCharPositions = TRUE)
00207     MILLIPOINT       Width;              // overall width used so far
00208 
00209     // All formatted text is anchored to a tab stop. There is a notional left tab at position 0
00210     // that anchors the start of the text. ActiveTabType/ActiveTabPos always contain information
00211     // about the currently active tab stop.
00212     TxtTabType       ActiveTabType;      // the type of the currently active tab stop
00213     MILLIPOINT       ActiveTabPos;       // its position
00214     VisibleTextNode* pLastTabVTN;        // the most recently fitted tab character object (maybe NULL)
00215 
00216     // AnchorPos contains the width of the text formatted up to the most recently encountered tab
00217     // character, in other words, the starting position of the field into which the section of text
00218     // of text anchored to the currently active tab is to be formatted.
00219     MILLIPOINT       AnchorPos;
00220 
00221     // When a non-left tab is encountered, RemainingSpace is set to the remaining space between the
00222     // tab character position (AnchorPos) and the position of the tab stop to which it advances
00223     // (ActiveTabPos). It is updated as text is formatted to the left of the tab stop.
00224     MILLIPOINT       RemainingSpace;
00225     // if the most recently encountered tab was a Decimal tab, keep track of what its decimal point
00226     // character is and whether we have met the decimal point already
00227     WCHAR            DecimalPointChar;
00228     BOOL             DecimalPointFound;
00229 
00230     // default constructor (no need to initialise RemainingSpace and DecimalPointFound)
00231     FormatState(MILLIPOINT AvailableWidth, BOOL SetPositions, VisibleTextNode* pFirstNode,
00232                 MILLIPOINT Indent, MILLIPOINT _CharPosOffset,
00233                 MILLIPOINT _ExtraOnChars, MILLIPOINT _ExtraOnSpaces):
00234         SetCharPositions(SetPositions),
00235         FitWidth(AvailableWidth), pFirstVTN(pFirstNode),
00236         CharPosOffset(_CharPosOffset),
00237         ExtraOnChars(_ExtraOnChars), ExtraOnSpaces(_ExtraOnSpaces),
00238         Width(Indent), ActiveTabType(LeftTab), ActiveTabPos(0), 
00239         pLastTabVTN(NULL), AnchorPos(Indent) {};
00240     void AdvanceBy(MILLIPOINT Advance, BOOL IsADecimalPoint);
00241     BOOL FinishTabSection(VisibleTextNode* pLastFormattedNode, BOOL IsLastTabSection);
00242     BOOL IsAvailable(MILLIPOINT CharWidth, BOOL IsATab, BOOL IsADecimalPoint);
00243 };
00244 
00245 /********************************************************************************************
00246 >   class TextLineInfo: public CC_CLASS_MEMDUMP
00247 
00248     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
00249     Created:    4/2/96
00250     Purpose:    passing line level info to/from functions
00251 ********************************************************************************************/
00252 
00253 class TextLineInfo : public CC_CLASS_MEMDUMP
00254 {
00255     CC_DECLARE_MEMDUMP(TextLineInfo);
00256 
00257 public:
00258     TextLineInfo();
00259 
00260     MILLIPOINT    SumCharAdvances;  // NB does not include last char tracking
00261     Justification justification;
00262     MILLIPOINT    LeftMargin;       // relative to start of line
00263     MILLIPOINT    RightMargin;      // relative to start of line
00264 
00265     MILLIPOINT    ParaLeftMargin;   // left margin from line level attribute (as opposed to object property for text on path)
00266     MILLIPOINT    ParaRightMargin;  // (NB. - the ParaLeftMargin value comes from either the LeftMargin or the FirstLine attribute)
00267     const TxtRuler* Ruler;
00268 
00269     BOOL          WordWrapping;
00270     INT32         NumChars;
00271     INT32         NumSpaces;
00272 };
00273 
00274 
00275 /********************************************************************************************
00276 >   class TextLine: public BaseTextClass
00277 
00278     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00279     Created:    21/12/94
00280     Purpose:    A TextLine gathers together all characters on a single line in a text story.
00281                 The TextLine object is responsible for rendering all its character node
00282                 children. It needs to do this because TextChars have no associated
00283                 bounds and so they can only render themselves relative to other chars.
00284     SeeAlso:    TextStory
00285 ********************************************************************************************/
00286 
00287 class TextLine: public BaseTextClass
00288 {
00289     CC_DECLARE_DYNAMIC(TextLine)
00290 
00291 public:
00292     TextLine();
00293     ~TextLine();
00294     TextLine(Node* ContextNode, AttachNodeDirection Direction);
00295     void Init();
00296     
00297     virtual Node* SimpleCopy();
00298     void CopyNodeContents(TextLine* NodeCopy);
00299     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00300 
00301     virtual CopyType GetCopyType();
00302     virtual INT32 ComplexCopy(CopyStage Stage, Range& RangeToCopy, Node** pOutput);
00303     virtual INT32 ComplexHide(UndoableOperation* pOp, Node* pNextNode);
00304 
00305     virtual BOOL IsSetCandidate() const     { return TRUE; }
00306     virtual BOOL IsCompound() const         { return TRUE; }        // See also NodeCompound
00307 
00308     virtual UINT32 GetNodeSize() const;     
00309     virtual void GetDebugDetails(StringBase* Str); // Can be deleted before we ship
00310     virtual String Describe(BOOL Plural, BOOL Verbose);            
00311 
00312     DocRect GetBlobBoundingRect();
00313     void RenderObjectBlobs(RenderRegion* pRRegion);
00314     void RenderTinyBlobs(RenderRegion* pRRegion);
00315     DocCoord GetTinyBlobPos();
00316 
00317     BOOL CreateNodeGroup(NodeGroup** ppNodeGroup, FormatRegion* pFormatRegion, BecomeA* pBecomeA);
00318     static TextLine* CreateEmptyTextLine(Node* pContextNode=NULL, AttachNodeDirection Direction=FIRSTCHILD);
00319 
00320     virtual BOOL ReCacheMetrics(FormatRegion* pFormmatRegion);
00321     BOOL Format(TextStoryInfo* pStoryInfo);
00322     BOOL EnsureNextLineOfParagraphHasSameLineLevelAttrs(UndoableOperation* pUndoOp);
00323     BOOL ReCalcLineInfo(TextLineInfo* pLineInfo);
00324     BOOL PositionCharsInLine(TextLineInfo* pLineInfo);
00325     BOOL CalcBaseAndDescentLine(MILLIPOINT* pBaseLine, MILLIPOINT* pDescentLine,
00326                                 MILLIPOINT LastDescentLine, BOOL FirstLine);
00327     BOOL SetCharMatrices(MILLIPOINT LinePos);
00328     BOOL FitTextToPath(TextStoryInfo* pPathInfo, MILLIPOINT LinePos);
00329     BOOL Wrap(UndoableOperation* pUndoOp, MILLIPOINT WrapWidth, MILLIPOINT Indent);
00330     VisibleTextNode* FindBreakChar(MILLIPOINT FitWidth, BOOL SetCharPositions,
00331                                    MILLIPOINT Indent, MILLIPOINT CharPosOffset = 0,
00332                                    MILLIPOINT ExtraOnChars = 0, MILLIPOINT ExtraOnSpaces = 0);
00333 
00334     TextLine* FindFirstLineOfParagraph();
00335     static BOOL IsAttrTypeLineLevel(CCRuntimeClass* pAttrType);
00336     BOOL AddChildLineLevelAttrsToSet(AttrTypeSet* pAttrSet);
00337 
00338     VisibleTextNode* FindCharAtDistAlongLine(MILLIPOINT Distance, BOOL* LeftHandSide);
00339     VisibleTextNode* FindFirstVTN() const;
00340     VisibleTextNode* FindLastVTN() const;
00341     EOLNode*         FindEOLNode() const;
00342     CaretNode*       FindCaret() const;
00343     TextLine*        FindNextLine() const;
00344     TextLine*        FindPrevLine() const;
00345     MILLIPOINT GetLastCharTracking();
00346 
00347     BOOL WholeLineSelected();
00348 
00349     BOOL WillLineWrapOnPath(FIXED16 xscale, MILLIPOINT PLength);
00350 
00351     // v2 file format functions
00352     virtual BOOL WritePreChildrenWeb(BaseCamelotFilter *pFilter);
00353     virtual BOOL WritePreChildrenNative(BaseCamelotFilter *pFilter);
00354     virtual BOOL WriteBeginChildRecordsWeb(BaseCamelotFilter* pFilter);
00355     virtual BOOL WriteBeginChildRecordsNative(BaseCamelotFilter* pFilter);
00356     virtual BOOL WriteEndChildRecordsWeb(BaseCamelotFilter* pFilter);
00357     virtual BOOL WriteEndChildRecordsNative(BaseCamelotFilter* pFilter);
00358 
00359     // private member access functions
00360     MILLIPOINT GetLineDescent() { return mLineDescent; }
00361     MILLIPOINT GetLineAscent()  { return mLineAscent; }
00362     MILLIPOINT GetLineSize()    { return mLineSize; }
00363     void SetLineDescent(MILLIPOINT Descent) { mLineDescent = Descent; }
00364     void SetLineAscent( MILLIPOINT Ascent)  { mLineAscent  = Ascent; }
00365     void SetLineSize(   MILLIPOINT Size)    { mLineSize    = Size; }
00366     void UpdateLineDescent(MILLIPOINT Descent) { if (Descent<mLineDescent) mLineDescent = Descent; }
00367     void UpdateLineAscent( MILLIPOINT Ascent)  { if ( Ascent>mLineAscent ) mLineAscent  = Ascent; }
00368     void UpdateLineSize(   MILLIPOINT Size)    { if (   Size>mLineSize   ) mLineSize    = Size; }
00369 
00370     Justification GetJustification()   { return mJustification; }
00371     MILLIPOINT    GetLineSpacing()     { return mLineSpacing; }
00372     FIXED16       GetLineSpaceRatio()  { return mLineSpaceRatio; }
00373     MILLIPOINT    GetParaLeftMargin()  { return mLeftMargin; }
00374     MILLIPOINT    GetParaFirstIndent() { return mFirstIndent; }
00375     MILLIPOINT    GetParaRightMargin() { return mRightMargin; }
00376     const TxtRuler* GetRuler()         { return mpRuler; }
00377     void SetJustification(  Justification justification) { mJustification  = justification; }
00378     void SetLineSpacing(    MILLIPOINT    Spacing)       { mLineSpacing    = Spacing; }
00379     void SetLineSpaceRatio( FIXED16       SpaceRatio)    { mLineSpaceRatio = SpaceRatio; }
00380     void SetParaLeftMargin( MILLIPOINT    Margin)        { mLeftMargin = Margin; }
00381     void SetParaFirstIndent(MILLIPOINT    Indent)        { mFirstIndent = Indent; }
00382     void SetParaRightMargin(MILLIPOINT    Margin)        { mRightMargin = Margin; }
00383     void SetRuler(          const TxtRuler* pRuler)      { if (*mpRuler != *pRuler) *mpRuler = *pRuler; }
00384 
00385     MILLIPOINT GetPosInStory() { return mPosInStory; }
00386     void SetPosInStory(MILLIPOINT pos) { mPosInStory=pos; }
00387 
00388 protected:
00389     MILLIPOINT GetEffectiveLeftMargin();
00390 private:
00391     MILLIPOINT mLineDescent;    // largest descent of any char in all fonts on the line
00392     MILLIPOINT mLineAscent;     // largest  ascent of any char in all fonts on the line
00393     MILLIPOINT mLineSize;       // largest   size  of any char in all fonts on the line
00394 
00395     Justification mJustification;   // cache for value read from attr stack
00396     MILLIPOINT    mLineSpacing;     // cache for value read from attr stack
00397     FIXED16       mLineSpaceRatio;  // cache for value read from attr stack
00398     MILLIPOINT mLeftMargin;         // cache for value read from attr stack
00399     MILLIPOINT mFirstIndent;        // cache for value read from attr stack
00400     MILLIPOINT mRightMargin;        // cache for value read from attr stack
00401     TxtRuler* mpRuler;              // cache for value read from attr stack
00402                                     // NB - this is a list object owned by this object
00403     MILLIPOINT mPosInStory;     // y position of base of line relative to story
00404 };
00405 
00406 #endif

Generated on Sat Nov 10 03:46:10 2007 for Camelot by  doxygen 1.4.4