osrndrgn.h

Go to the documentation of this file.
00001 // $Id: osrndrgn.h 1282 2006-06-09 09:46:49Z 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 
00099 // OSRNDRGN.H
00100 //
00101 // Created: 29/6/93 by Will
00102 //
00103 
00104 #ifndef INC_OSRNDRGN
00105 #define INC_OSRNDRGN
00106 
00107 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "paths.h"    // We access path objects directly (we are a friend) - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "wincoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "winrect.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "rendtype.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "gbrush.h"
00113 //#include "gconsts.h" // Test only - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "rrcaps.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 
00116 class GradFillAttribute;
00117 class BitmapFillAttribute;
00118 class LinearFillAttribute;
00119 class RadialFillAttribute;
00120 class ConicalFillAttribute;
00121 class SquareFillAttribute;
00122 class ThreeColFillAttribute;
00123 class FourColFillAttribute;
00124 class KernelBitmap;
00125 class DocView;
00126 class CRgn;
00127 class CPalette;
00128 
00129 // Used for rendering text via GDI
00130 // (It is a simple cache system).
00131 class OSRRFontInfo
00132 {
00133 public:
00134     OSRRFontInfo();
00135 
00136 public:
00137     WORD Typeface;
00138     BOOL Bold;
00139     BOOL Italic;
00140     MILLIPOINT Width;
00141     MILLIPOINT Height;
00142     ANGLE Rotation;
00143     wxFont *pRenderFont;
00144     wxFont *pOldFont;
00145 };
00146 
00147 
00148 class EORCacheClass
00149 {
00150 public:
00151     EORCacheClass() : Valid(FALSE) {}
00152 
00153     BOOL Valid;
00154     DocColour SourceColour;
00155     COLORREF EORColour;
00156 };
00157 
00158 
00159 // This is the size of the buffer we use when flattening paths - the maximum sensible
00160 // size is 16384 points, as this is 64k, and obviosuly the longest polyline Win16
00161 // can handle.
00162 #define SIZEOF_POLYLINE_BUFFER  8192
00163 
00164 /********************************************************************************************
00165 
00166 >   class OSRenderRegion : public RenderRegion
00167 
00168     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00169     Created:    11/5/93
00170     Purpose:    Encapsulates rendering using the OS. (GDI, RiscOS, etc).
00171                 This object is created when something needs rendering using the OS calls
00172                 instead of Gavins routines.  This will be ALL THE TIME for the moment.
00173                 See RenderRegion notes for more general details of this class.
00174 
00175 ********************************************************************************************/
00176         
00177 class CCAPI OSRenderRegion : public RenderRegion
00178 {
00179     CC_DECLARE_DYNAMIC(OSRenderRegion)
00180 
00181 public:
00182     // Construction and creation
00183     // This should always be used to create OSRenderRegions
00184     static RenderRegion* Create(DocRect ClipRegion, 
00185                                 Matrix ConvertMatrix, 
00186                                 FIXED16 ViewScale,
00187                                 RenderType rType,
00188                                 View* pView = NULL,
00189                                 BOOL UseOSRendering = FALSE,
00190                                 BOOL bForce32BPP = FALSE);
00191 
00192     ~OSRenderRegion();
00193     OSRenderRegion(const OSRenderRegion &other);
00194 
00195     static BOOL Init();
00196     static void FlushEORCache(void);
00197 
00198     virtual BOOL AttachDevice(View*, wxDC*, Spread* SpreadToAttach = NULL, bool fOwned = false );
00199     virtual BOOL InitDevice();
00200     
00201     // Functions called as rendering starts and stops
00202     BOOL StartRender();
00203     BOOL StopRender();
00204 
00205     // Enable/Disable solid-colour (no-dither) plotting
00206     virtual void SetSolidColours(BOOL SetSolid);
00207 
00208     // Functions that actually draw somthing
00209     void DrawPathToOutputDevice(Path* PathToDraw, PathShape shapePath=PATHSHAPE_PATH);
00210     void DrawRect(DocRect* PathToDraw);
00211     void DrawDragRect(DocRect* PathToDraw);
00212     virtual void DrawDragBounds(DocRect *RectToRender);
00213     virtual void DrawDashLine(const DocCoord &StartPoint, const DocCoord &EndPoint);
00214     void DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint);
00215     void DrawPixel(const DocCoord &Point);
00216     void DrawCross(const DocCoord &Point, const UINT32 Size);
00217     void DrawBlob(DocCoord p, BlobType type);
00218 
00219     void DrawBitmap(const DocCoord &Point, KernelBitmap* pBitmap);
00220     void DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID = NULL);
00221     BOOL DrawTransformedBitmap(NodeBitmap *pNodeBitmap);
00222 
00223     void DrawBitmapBlob(const DocCoord &Point, KernelBitmap* BlobShape);
00224     void DrawBitmapBlob(const DocCoord &Point, ResourceID resID );
00225 
00226     static wxSize GetFixedDCPPI (wxDC &dc);
00227 
00228     // Function to draw a bitmap into the render region using a mask, and
00229     // and equivalent function to do the same, only colour separating it as it goes
00230     // The Separated version is called by this one if colour seps are enabled
00231     virtual SlowJobResult DrawMaskedBitmap(const DocRect &Rect, KernelBitmap* pBitmap, 
00232                                            MaskedRenderRegion* pMask, ProgressDisplay *Progress);
00233 protected:
00234     virtual SlowJobResult DrawSeparatedMaskedBitmap(const DocRect &Rect, KernelBitmap* pBitmap, 
00235                                            MaskedRenderRegion* pMask, ProgressDisplay *Progress);
00236 
00237 public:
00238     void DrawFixedSystemText(StringBase *TheText, DocRect &BoundsRect, UINT32 uFormat = DEFAULT_TEXT_FORMATTING);
00239     void SetFixedSystemTextColours(DocColour *TextCol, DocColour *Background);
00240     void GetFixedSystemTextSize(StringBase *TheText, DocRect *BoundsRect, double* atDpi = NULL);
00241 
00242     static void GetBlobRect( FIXED16, const DocCoord& BlobPoint, BlobType bType, DocRect *pResult );
00243 
00244     BOOL RenderGradFillPath(Path *, GradFillAttribute* );
00245     BOOL RenderBitmapFill  (Path *, BitmapFillAttribute* );
00246 
00247     virtual BOOL RenderChar(WCHAR ch, Matrix* pMatrix);
00248 
00249     // Conversion functions
00250     static WinRect DocRectToWin( View *pView, const Matrix& RenderMatrix, 
00251                                  const DocRect& docrect,
00252                                  INT32 leftshift, INT32 topshift, INT32 rightshift, INT32 bottomshift,
00253                                  BOOL MightClip = FALSE);
00254     //static WinRect DocRectToWin( const Matrix& RenderMatrix, const DocRect& docrect,
00255     //                           const INT32 dpi);
00256 
00257     static WinRect DocRectToWin( const Matrix& RenderMatrix, const DocRect& docrect,
00258                                  const double dpi);
00259     // Same as above but used for exporting bitmaps to try and fix pixel problems
00260     static WinRect BitmapDocRectToWin( Matrix& RenderMatrix, const DocRect& docrect,
00261                                        const double dpi);
00262     static BOOL CalculateGavinOffsetsWinRect( const Matrix& RenderMatrix,
00263                                               const DocRect& DRect,
00264                                               const double dpi,
00265                                               GMATRIX* GMat,
00266                                               BOOL bCentralise,
00267                                               double* pdXCentralAdjust,
00268                                               double* pdYCentralAdjust);
00269 
00270     static DocRect WinRectToDoc( const Matrix &RenderMatrix,
00271                                  const WinRect& WRect,
00272                                  const double dpi);
00273 
00274     static BOOL DoBetterLines;                              // TRUE for GDraw lnies, FALSE for GDI
00275 
00276     static MILLIPOINT GetHitTestRadius(DocView *pDocView);
00277 
00278     BOOL StrokeProperly( Path *const );
00279 
00280     // Function to allow render regions to say what they can not render
00281     virtual void GetRenderRegionCaps(RRCaps* pCaps);
00282 
00283 protected:
00284     
00285     static INT32 HitTestRadius;             // how close a click must be to hit-detect
00286 
00287     // Constructor (protected as you should use Create() )
00288     OSRenderRegion(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale = 1);
00289 
00290     // Various startup and shutdown functions
00291     
00292     void InitClipping();
00293     void DeInitClipping();
00294 
00295     void InitAttributes();
00296     void DeInitAttributes();
00297 
00298     // These functions are called from the RenderRegion base class when attributes are changed.
00299     void SetLineAttributes(ChangeLineAttrType Type = CHANGELINEATTR_ALL);
00300     void SetFillAttributes(ChangeAttrType Type = CHANGEATTR_ALL);
00301     void SetOSDrawingMode();
00302     void SetQualityLevel();
00303 
00304     // Conversion functions
00305     Coord DocCoordToOS256(const DocCoord& DocPoint);
00306     WinCoord DocCoordToWin(const DocCoord& DocPoint);
00307     WinRect DocRectToWin( const DocRect& docrect, INT32 leftshift, INT32 topshift,
00308                           INT32 rightshift, INT32 bottomshift, BOOL MightClip = FALSE)
00309                         { return DocRectToWin(RenderView, RenderMatrix, docrect, 
00310                                               leftshift, topshift,
00311                                               rightshift, bottomshift, MightClip ); }
00312 
00313     // Render fills.
00314     BOOL RenderRadialFill   ( Path *PathToDraw, RadialFillAttribute     *Fill );
00315     BOOL RenderLinearFill   ( Path *PathToDraw, LinearFillAttribute     *Fill );
00316     BOOL RenderConicalFill  ( Path *PathToDraw, ConicalFillAttribute    *Fill );
00317     BOOL RenderSquareFill   ( Path *PathToDraw, SquareFillAttribute     *Fill );
00318     BOOL RenderThreeColFill ( Path *PathToDraw, ThreeColFillAttribute   *Fill );
00319     BOOL RenderFourColFill  ( Path *PathToDraw, FourColFillAttribute    *Fill );
00320 
00321     static MILLIPOINT CalcDistance(DocCoord a, DocCoord b);
00322     static void MakeEllipticalPath(Path *pPath, DocCoord Parallel[4]);
00323 
00324 #if 0
00325     // Functions to help with line arrows
00326     void DrawLineArrow(ArrowRec &ArrowToDraw, const Coord &Centre, const Coord &Direction);
00327 #endif
00328 
00329     // Helper functions
00330     void CreateNewPen();
00331     void SelectNewPen();
00332     void CreateNewBrush();
00333     void SelectNewBrush();
00334 
00335     BOOL SelectNewFont(WORD Typeface, BOOL Bold, BOOL Italic, 
00336                        MILLIPOINT Width, MILLIPOINT Height, ANGLE Rotation);
00337 
00338     void MakeDashType(DashRec&, DashType*);
00339 
00340     // Functions to render a Path
00341     void RenderPath32( Path *DrawPath);
00342     void RenderPath( Path *DrawPath );
00343 
00344     // low-level internal bezier primitives
00345     BOOL RawRenderPath32( Path *const );
00346     BOOL RawRenderPath( DocCoord *const, PathVerb *const, INT32 NumCoords, INT32 *PolyCount, INT32 *Count,
00347                         INT32 Flatness = 0, INT32 *pActualFlatness = NULL );
00348     BOOL SetClipToPathTemporary( Path *const);
00349 
00350     // this macro for use in RawRenderPath calls
00351     #define NORMALPATH(pp)  pp->GetCoordArray(), pp->GetVerbArray(), pp->GetNumCoords()
00352 
00353     // Bezier flattening functions
00354     BOOL Bezier(INT32 Px0,INT32 Py0, INT32 Px1,INT32 Py1, INT32 Px2,INT32 Py2, INT32 Px3,INT32 Py3, INT32 Flatness);
00355     BOOL Split(INT32 Px0,INT32 Py0, INT32 Px1,INT32 Py1, INT32 Px2,INT32 Py2, INT32 Px3,INT32 Py3, INT32 Flatness);
00356     INT32 CalcPathFlattening();
00357 
00358     // misc
00359     INT32    MPtoLP(MILLIPOINT MPtoConvert);
00360     wxColour CalcEORColour( DocColour &Wanted, COLORREF = RGB(255,255,255) );
00361     void CalcLogBrush(wxBrush*, DocColour &);
00362 //  BOOL NewPolyDraw( const POINT*, const BYTE*, INT32);
00363 
00364     wxPoint FindBitmapOrigin(DocCoord Centre, INT32 Width, INT32 Height);
00365 
00366 // Variables
00367 protected:
00368 
00369     MILLIPOINT CalcScaledPixelWidth();
00370     MILLIPOINT CalcPixelWidth();
00371 
00372     // The rendering flags
00373     struct
00374     {
00375         BOOL Metafile   : 1;        // TRUE if metafile
00376 //      BOOL GDI32      : 1;        // TRUE if can use GDI32 calls
00377         BOOL ValidPen   : 1;        // TRUE if RenderPen is correct
00378         BOOL ValidBrush : 1;        // TRUE if RenderBrush is correct
00379         BOOL UsePalette : 1;        // TRUE if using special palette
00380     } RFlags;
00381 
00382     // The clip region
00383     wxRegion*  OSClipRegion;
00384     wxPalette* OldPalette;          // NULL if no old palette
00385 
00386     GBrush GDrawBrush;              // special Gavin-compatible brush
00387 
00388 protected:
00389     void GetValidPen();
00390     void GetValidBrush();
00391 
00392     // The position in the polygon array to insert points at and the array
00393     static wxPoint PointArray[SIZEOF_POLYLINE_BUFFER];
00394 
00395     // cache for EOR colour
00396     static EORCacheClass EORCache;
00397     
00398     INT32 InsertPos;
00399 
00400     // The size of a pixel
00401     FIXED16 PixelScale;
00402 
00403     INT32   nFillStyle ;
00404 
00405     // A selection of pens and brushes for drawing with
00406     INT32   CurrentPen;
00407     INT32   CurrentBrush;
00408     wxPen   RenderPen[2];
00409     wxBrush RenderBrush[2];
00410 //  wxPen   *OldPen;
00411 //  wxBrush *OldBrush;
00412     wxFont  *OldFont;               // Used for supporting "FixedSystem" font rendering
00413 
00414     OSRRFontInfo FontInfo;
00415 
00416     // The brush origin
00417     wxPoint NewBrushOrg;
00418 
00419     // This render regions caps. We keep a cached version here as it can be needed in rendering
00420     RRCaps Caps;
00421 
00422 protected:
00423     BYTE *SepTables;                // NULL, or a pointer to colour separation tables
00424 };
00425 
00426 /********************************************************************************************
00427 
00428 >   class PaperRenderRegion : public OSRenderRegion
00429 
00430     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00431     Created:    28/06/94
00432     Purpose:    Provide a fast way of rendering paper.  One of these regions is used to
00433                 render paper on screen, to avoid any lag we might get from using a bitmap
00434                 type render region (e.g. GRenderRegion).
00435     SeeAlso:    OSRenderRegion; GRenderRegion; DocView
00436 
00437 ********************************************************************************************/
00438 
00439 class PaperRenderRegion : public OSRenderRegion
00440 {
00441     CC_DECLARE_DYNAMIC(PaperRenderRegion)
00442 
00443 public:
00444     // Construction and creation
00445     PaperRenderRegion(DocRect ClipRect, Matrix ConvertMatrix, FIXED16 ViewScale);
00446     ~PaperRenderRegion();
00447 
00448     // Changing the render destination.
00449     BOOL AttachDevice(View *pView, Spread *pSpread, wxDC *pDC, Matrix& ViewMatrix,
00450                       FIXED16 ViewScale, DocRect& ClipRect, bool fOwned = false );
00451     void DetachDevice();
00452 
00453     virtual BOOL InitDevice();
00454 };
00455 
00456 #endif

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