/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef EXGI_GDI_DC #define EXGI_GDI_DC #include "TD_PackPush.h" #include "OdVector.h" #define STL_USING_SET #define STL_USING_MAP #include "OdaSTL.h" /* \details This class is used for working with DIBSECTION through GDI context (ExGiGDIDC) to reflect data changes in the mirror transparency mode (for more information, see ExGiGDIDC::ExGDIDCTransparencyMode). */ class OdExGiGDIBytesReflector { friend class ExGiGDIDC; void** pIn; void* pMirror; public: /* \details Constructor for the OdExGiGDIBytesReflector class. Accepts input byte data. \param pBytes [in] Input bytes. */ OdExGiGDIBytesReflector( void** pBytes ) { pIn = pBytes; pMirror = NULL; } /* \details Fills the input array with data from the specified source source. \param pSrc [in] Data source. \param Size [in] Data size. \remarks The mirror is also filled if it exists (in the mirror transparency mode). */ void fillBy( const void* pSrc, size_t Size ) { memcpy( *pIn, pSrc, Size ); if( pMirror ) memcpy( pMirror, pSrc, Size ); } /* \details Returns input bytes destination. \returns Pointer to input bytes destination. */ const void* in() const { return ( pIn ? *pIn : NULL ); } /* \details Returns mirror destination. \returns Pointer to mirror destination. */ const void* mirror() const { return pMirror; } }; /* \details This class represents GDI device context. */ class ExGiGDIDC { typedef std::pair< OdUInt32, OdUInt32 > PenStylePair; // class OdGDIStyler { class GDIPenStyle { PenStylePair m_pair; DWORD m_sz; DWORD m_style[ 17 ]; bool m_isCustom; OdUInt32 m_nStyleBase; DWORD m_width; public: GDIPenStyle(); GDIPenStyle( const PenStylePair& ); GDIPenStyle( DWORD sz, const DWORD* pStyle ); void set( const PenStylePair& ); void set( DWORD sz, const DWORD* pStyle ); bool isPixelVisible( OdUInt32 nPixel ) const; void setWidth( DWORD w ) { m_width = w; } DWORD width() const { return m_width; } }; class GDIBrushStyle { enum BrushType { kMono, kPattern }; BrushType m_type; bool m_bVisibleMono; ULONG_PTR m_curPattern; OdUInt8 m_pattern[ 8 ]; #ifndef _WIN32_WCE void createPatternForHatch( OdUInt8 pat, bool bClear = true ); #endif public: GDIBrushStyle(); ~GDIBrushStyle(); void set( const LOGBRUSH& lb ); bool isPixelVisible( OdUInt32 nRow, OdUInt32 nCol ) const; }; GDIPenStyle m_penStyle; GDIBrushStyle m_brushStyle; enum GDIPenStyles { kSolid = 0, kDash, kDot, kDashDot, kDashDotDot, kDot3, kNull, kLastPenStyle }; PenStylePair prePenStyles[ kLastPenStyle ]; ExGiGDIDC* m_exdc; public: OdGDIStyler(); ~OdGDIStyler(); void setDC( ExGiGDIDC* pDc ) { m_exdc = pDc; } #ifndef _WIN32_WCE void setGDIPenStyle( const EXTLOGPEN& elp ); #endif void setGDIPenStyle( const LOGPEN& pen ); void setCustomPenStyle( DWORD sz, const DWORD* pStyle ); DWORD getPenWidth() const { return m_penStyle.width(); } void setGDIBrushStyle( const LOGBRUSH& lb ); bool isPenPixelVisible( OdUInt32 nPixel ) const; bool isBrushPixelVisible( OdUInt32 nRow, OdUInt32 nPixel ) const; }; HDC m_hTargetDC; mutable HDC m_hMemDC; mutable HBITMAP m_memBitmap; mutable int m_width; mutable int m_height; enum ExDCFlags { kMirrorMode = 1, // Mirror DC enabled kAlphaMode = 1 << 1, // Semi-transparent alpha set kHasChanges = 1 << 2, kAlphaTrp = 1 << 3, // Alpha-transparency enabled kRasterTrp = 1 << 4, // Raster image transparency enabled kRasterMode = 1 << 5 // Raster image transparency pass }; OdGDIStyler m_styler; inline void setNeedSync( bool bNeed = true ) const { SETBIT( m_flags, kHasChanges, bNeed ); } inline bool needSync() const { return GETBIT( m_flags, kHasChanges ); } mutable OdVector< void* > m_memObjects; mutable OdUInt8 m_flags; OdUInt8 m_alpha; COLORREF m_color; bool initMemDC() const; void releaseMemDC( bool bResetSize = true ) const; //presented points processing struct presentedPoint { int x; int y; presentedPoint( int _x, int _y ) : x( _x ), y( _y ) {} bool operator<( const presentedPoint& pt ) const { if( y < pt.y ) return true; else if( y == pt.y ) { if( x < pt.x ) return true; } return false; } }; std::set< presentedPoint > m_presentedPoints; OdUInt8 m_bCheckFlag; enum PresentedPointsCheck { kNone = 0, kAll = 1, kEnd = 2 }; bool processPresentedPoint( int x, int y ); //Styles void syncDCStyles(); //Save/Restore DC std::map< int, int > m_memStack; inline bool isYOnScreen( int y ) const { return y >= 0 && y <= m_height; } inline bool isXOnScreen( int x ) const { return x >= 0 && x <= m_width; } inline bool isPointOnScreen( int x, int y ) const { return isXOnScreen( x ) && isYOnScreen( y ); } bool checkPixel( const OdUInt8* pBits, int w, OdUInt8 format, OdUInt8 bpp, int x, int y, COLORREF& color, OdUInt8& alpha ); COLORREF processPixelColorRasterOperation( int x, int y, COLORREF color, DWORD rop ); class BitsCache { OdUInt8* m_pCache = nullptr; HANDLE m_hDIB = 0; int m_xDest = 0; int m_yDest = 0; int m_wDest = 0; int m_hDest = 0; int m_scanLineSize = 0; BITMAPINFOHEADER m_bi = { 0 }; public: BitsCache() : m_pCache( nullptr ) {}; ~BitsCache() { if( m_pCache ) clearCache(); }; bool hasCache() const { return m_pCache != nullptr; } void clearCache(); void makeCache( ExGiGDIDC* pExDc ); COLORREF getCachedColor( int x, int y ) const; //VIS-3181: avoid SetPixel by SetDIBits for memory bitmap bool cacheToBitmap( ExGiGDIDC* pExDc ); bool setCacheColor( int x, int y, COLORREF color ); }; BitsCache m_bitsCache; public: /* \details Supported transparency modes for a device. \remarks If transparency mode is set to kNoTransparency, all transparency data is discarded and the drawn objects (both transparent and not) have fully opaque pixels. If you need to draw a transparent object, you need to get information about current pixel data that is about to be drawn to device and apply transparency to it. Typical algorithm to apply transparency is the following: 1. Get pixel color of an original device using the getPixel() method; 2. Prepare a new pixel by applying transparency value to the retrieved pixel; 3. Set new pixel to the device using the setPixel() method; With the kDirectTransparency mode current pixel color is retrieved directly from a device and after applying transparency, the pixel is set to this device. Some printing devices do not support getPixel() method so there is no way to directly get color of a pixel that is drawn. In this case, the kMirrorTransparency mode should be used. In the kMirrorTransparency mode an additional device context is created that is used for drawing pixels to a bitmap (the bitmap is stored in memory). This way it is possible to retrieve current pixel color from a bitmap in memory. The retrieved pixel data is processed using the alpha value, and resulting pixel is set to a device, according to the algorithm. In general, the kMirrorTransparency mode is slower, consumes more memory but works for more devices to support transparency. */ enum ExGDIDCTransparencyMode { /* No transparency support.*/ kNoTransparency = 0, /* Transparency using additional DC.*/ kMirrorTransparency = 1, /* Transparency using the same DC.*/ kDirectTransparency = 2, /* Process only raster images transparency using additional DC.*/ kRasterTransparency = 3 }; //DOM-IGNORE-BEGIN enum ExDCObjects { kBitmap = 0, kDIBSectionBitmap = 1, kUseTheSame, kAllObjects }; //DOM-IGNORE-END /* \details Constructor for the ExGiGDIDC class. \param transparencyMode [in] Supported transparency mode. */ ExGiGDIDC( ExGDIDCTransparencyMode transparencyMode ); /* \details Destructor for the ExGiGDIDC class. */ ~ExGiGDIDC(); /* \details Checks whether the "mirror mode" is used for providing transparency support. \returns true if the "mirror mode" is used, false otherwise. \remarks For more information, see . */ inline bool isMirrorMode() const { return GETBIT( m_flags, kMirrorMode ); } //inline bool isDirectMode() const { return GETBIT( m_flags, kAlphaTrp ) && !GETBIT( m_flags, kMirrorMode ); } /* \details Returns handle to the target (main) device context. Must be always present. \returns Handle to the target device context. */ HDC targetDC() const { return m_hTargetDC; } /* \details Returns handle to the additional device context. The retrieved device context is used for writing to a bitmap image (stored in memory) in the "mirror transparency mode". \returns Handle to the additional device context. */ HDC memoryDC() const { initMemDC(); return m_hMemDC; } /** \details Retrives handle to the memory bitmap. \returns Handle to the memory bitmap. */ HBITMAP memoryBitmap() const { return m_memBitmap; } /* \details Sets a target device context. \param hdc [in] Handle to the target device context. \returns Handle to the target device context. \remarks This method also releases memory (additional) device context if it is present. */ HDC& setDC( HDC hdc ) { m_hTargetDC = hdc; releaseMemDC(); return m_hTargetDC; } /* \details Sets sizes for the context. \param w [in] Width in pixels. \param h [in] Height in pixels. */ void setSizes( int w, int h ) { m_width = w; m_height = h; } //Wrapped members HGDIOBJ selectObject( HGDIOBJ obj, ExDCObjects type = kUseTheSame ); BOOL deleteMirrorObject( ExDCObjects type ); /* \details Sets the new background color. \param color [in] Background color. \returns Previous background color value. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ COLORREF setBkColor( COLORREF color); /* \details Sets the background mode. \param mode [in] Background mode. \returns Previous background mode. \remarks The background mode can be one of the following: NameValueDescription TRANSPARENT 1 Background is not changed before drawing OPAQUE 2 Background is filled with the current background color before the text, hatched brush, or pen is drawn
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int setBkMode( int mode ); //Wrapped geometry methods /* \details Draws a line from the current position up to the specified point specified. \param x [in] X coordinate of the line endpoint. \param y [in] Y coordinate of the line endpoint. \returns true if the line is successfully drawn, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool lineTo( int x, int y ); /* \details Updates the current position and optionally retrieves the current position before the update. \param x [in] X coordinate of the new position. \param y [in] Y coordinate of the new position. \param lpp [out] Receives previous position. \returns true if the position is successfully updated, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool moveToEx( int x, int y, LPPOINT lpp ); /* \details Sets the pixel color of the point with the specified coordinates. \param x [in] X coordinate of the point. \param y [in] Y coordinate of the point. \param color [in] Pixel color. \returns RGB value of color that is actually drawn. This value can be different from the provided 'color' value if an approximation of that color is used. If this method fails it returns -1. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ COLORREF setPixel( int x, int y, COLORREF color ); /* \details Draws a closed polygon. \param apt [in] Pointer to a array of points. \param cpt [in] Count of points in the array. Must be greater than or equal to 2. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool polygon( const POINT* apt, int cpt ); /* \details Draws a rectangle. \param left [in] X coordinate of the upper-left corner of the rectangle. \param top [in] Y coordinate of the upper-left corner of the rectangle. \param right [in] X coordinate of the lower-right corner of the rectangle. \param bottom [in] Y coordinate of the lower-right corner of the rectangle. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool rectangle( int left, int top, int right, int bottom ); /* \details Draws a polyline. \param apt [in] Pointer to a array of points. \param cpt [in] Count of points in the array. Must be greater than or equal to 2. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool polyline( const POINT* apt, int cpt ); #ifndef _WIN32_WCE /* \details Draws a sequence of closed polygons. \param apt [in] Pointer to a array of points. \param asz [in] Pointer to an array of integers defining corresponding points count for each polygon. Must be greater than or equal to 2. \param csz [in] Total number of polygons. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool polyPolygon( const POINT* apt, const int* asz, int csz ); /* \details Sets the polygon fill mode for functions that fill polygons. \param mode [in] Fill mode. \returns Value that represents previously set fill mode, or returns 0 if the method fails. \remarks The fill mode can be one of the following: NameValueDescription ALTERNATE 1 Fills the area between odd-numbered and even-numbered polygon sides on each scan line WINDING 2 Fills any region with a nonzero winding value
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int setPolyFillMode( int mode ); /* \details Opens a path bracket in the target device context. \returns true if the method executes successfully, false otherwise. \remarks After a path bracket is open, an application can call GDI drawing functions to define the points that lie in the path. To close an open path bracket, call the endPath() method. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool beginPath(); /* \details Draws a set of line segments and Bezier curves. \param apt [in] Pointer to a array of points. \param aj [in] Pointer to an array that specifies how each point in the array is used. \param cpt [in] Total number of points. \returns true if the method executes successfully, false otherwise. \remarks The 'aj' parameter can be one of the following: NameValueDescription PT_LINETO 2 Indicates that a line is drawn from the current position to this point, which then becomes the new current position PT_BEZIERTO 4 Indicates that this point is a control point or ending point for a Bezier curve. PT_BEZIERTO types always occur in sets of three where the first two PT_BEZIERTO points are the control points, and the third PT_BEZIERTO point is the ending point. The current position specifies the starting point for the Bezier curve PT_MOVETO 6 Indicates that this point starts a disjoint figure. This point becomes the new current position
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool polyDraw( const POINT* apt, const BYTE* aj, int cpt ); /* \details Closes a path bracket and selects the path defined by the bracket in the target device context. \returns true if the method executes successfully, false otherwise. \remarks This method should be executed after the call to the endPath() method and defining the points that lie in the path. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool endPath(); /* \details Strokes the outline of the path by using the current pen. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool strokePath(); /* \details Closes any open figures in a path, strokes the outline of the path by using the current pen, and fills its interior by using the current brush. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool strokeAndFillPath(); /* \details Specifies the intercharacter spacing. \param extra [in] Intercharacter spacing value in logical units. \returns Previous intercharacter spacing value if the method executes successfully, otherwise returns 0x80000000. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int setTextCharacterExtra( int extra ); #endif /* \details Sets color of the text. \param align [in] Text alignment by using a mask of the values. \returns Previous text alignment settings if the method executes successfully, otherwise returns 0xFFFFFFFFL (GDI_ERROR). \remarks The 'align' parameter can be one or combination of the following values: NameDescription TA_BASELINE The reference point is on the base line of the text TA_BOTTOM The reference point is on the bottom edge of the bounding rectangle TA_TOP The reference point is on the top edge of the bounding rectangle TA_CENTER The reference point is aligned horizontally with the center of the bounding rectangle TA_LEFT The reference point is on the left edge of the bounding rectangle TA_RIGHT The reference point is on the right edge of the bounding rectangle TA_NOUPDATECP The current position is not updated after each text output call. The reference point is passed to the text output function TA_RTLREADING (Only for Hebrew or Arabic fonts) The text is written from right to left reading order, as opposed to the default left to right order TA_UPDATECP The current position is updated after each text output call
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ UINT setTextAlign( UINT align ); /* \details Specifies the text color to the target device context. \param color [in] Color of the text. \returns Previous text color if the method executes successfully, otherwise returns 0xFFFFFFFF (CLR_INVALID). \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ COLORREF setTextColor( COLORREF color ); /* \details Draws text using the currently selected font, background color, text color and some other optional parameters. \param x [in] X coordinate of the reference point used to position the string. \param y [in] Y coordinate of the reference point used to position the string. \param options [in] Options indicating how to use the application-defined rectangle. \param lprect [in] Optional rectangle that is used for clipping, opaquing, or both. \param lpString [in] String that represents the text to draw. \param c [in] Length of the string. \param lpDx [in] Pointer to an optional array of values that indicate the distance between origins of adjacent character cells. \returns true if the method executes successfully, false otherwise. \remarks The 'options' parameter can be one or combination of the following values: NameDescription ETO_CLIPPED Text is clipped to the rectangle ETO_GLYPH_INDEX The string of text to draw is returned from GetCharacterPlacement() method and should be parsed directly by GDI as no further language-specific processing is required. Glyph indexing only applies to TrueType fonts, but the flag can be used for bitmap and vector fonts to indicate that no further language processing is necessary ETO_IGNORELANGUAGE Reserved for system use ETO_NUMERICSLATIN To display numbers, use European digits ETO_NUMERICSLOCAL To display numbers, use digits appropriate to the locale ETO_OPAQUE The current background color is used to fill the rectangle ETO_PDY The current position is not updated after each text output call ETO_RTLREADING (Only for Hebrew or Arabic fonts) The text is written from right to left reading order, as opposed to the default left to right order
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool extTextOutW( int x, int y, UINT options, const RECT* lprect, LPCWSTR lpString, UINT c, const INT* lpDx ); #ifndef _WIN32_WCE /* \details Sets the graphics mode for the target device context. \param mode [in] Graphics mode. \returns true if the method executes successfully, false otherwise. \remarks The 'options' parameter can be one or combination of the following values: NameDescription GM_COMPATIBLE Sets the graphics mode that is compatible with 16-bit Windows. This is the default mode. If this value is specified, the application can only modify the world-to-device transform by calling functions that set window and viewport extents and origins, but not by using SetWorldTransform() or ModifyWorldTransform() GM_ADVANCED Sets the advanced graphics mode that allows world transformations. This value must be specified if the application sets or modifies the world transformation for the target device context
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool setGraphicsMode( int mode ); /* \details Sets a 2D transformation matrix for linear transformation between world space and page space for the target device context. \param tr [in] Pointer to 2D transformation matrix. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool setWorldTransform( const XFORM* tr ); /* \details Modifies the world transformation for a target context using the specified mode. \param tr [in] Pointer to 2D transformation matrix. \param mode [in] Transformation mode. \returns true if the method executes successfully, false otherwise. \remarks The 'mode' parameter can be one of the following: NameDescription MWT_IDENTITY Resets the current world transformation by using the identity matrix MWT_LEFTMULTIPLY The new transformation data = tr * currentMatrix MWT_RIGHTMULTIPLY The new transformation data = currentMatrix * tr
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool modifyWorldTransform( const XFORM* tr, DWORD mode ); #endif /* \details Saves the current state of the target device context. \returns Value of the saved state or 0 if the method fails. \remarks The saved state can be restored with the RestoreDC() method. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int saveDC(); /* \details Restores a device context to the specified state. \param dc [in] The saved state to restore. \returns true if the method executes successfully, false otherwise. \remarks The saved state can be restored only for the same device context for which it was created. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool restoreDC( int dc ); #ifndef _WIN32_WCE /* \details Selects the current path as a clipping region for a device context, combining the new region with any existing clipping region using the specified mode. \param mode [in] Mode in which the path is selected. \returns true if the method executes successfully, false otherwise. \remarks The 'mode' parameter can be one of the following: NameDescription RGN_AND The new clipping region includes the intersection of the current clipping region and the current path RGN_COPY The new clipping region is the current path RGN_DIFF The new clipping region includes the areas of the current clipping region excluding areas of the current path RGN_OR The new clipping region includes the union (combined areas) of the current clipping region and the current path RGN_XOR The new clipping region includes the union of the current clipping region and the current path but without the overlapping areas
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool selectClipPath( int mode ); #endif /* \details Creates a new clipping region from the intersection of the current clipping region and the specified rectangle. \param left [in] X coordinate of the upper-left corner of the rectangle. \param top [in] Y coordinate of the upper-left corner of the rectangle. \param right [in] X coordinate of the lower-right corner of the rectangle. \param bottom [in] Y coordinate of the lower-right corner of the rectangle. \returns true if the method executes successfully, false otherwise. NameDescription NULLREGION Region is empty SIMPLEREGION Region consists of one rectangle COMPLEXREGION Region consists of more than one rectangle ERROR An error occurred
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int intersectClipRect( int left, int top, int right, int bottom ); /* \details Fills a rectangle by using the specified brush. This function includes the left and top borders, but excludes the right and bottom borders of the rectangle. \param lprc [in] A pointer to a rectangle containing area to fill. \param hbr [in] Handle to the brush that is used to fill the rectangle. \returns non-zero value if the method executes successfully, otherwise returns 0. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int fillRect( const RECT* lprc, HBRUSH hbr ); #ifndef _WIN32_WCE /* \details Sets the bitmap stretching mode for the target device context. \param mode [in] Stretching mode. \returns Previous stretching mode value if the method executes successfully, otherwise returns 0. \remarks The 'mode' parameter can be one of the following: NameDescription BLACKONWHITE Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves black pixels at the expense of white pixels COLORONCOLOR Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information HALFTONE Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination block of pixels approximates the color of the source pixels STRETCH_ANDSCANS Same as BLACKONWHITE STRETCH_DELETESCANS Same as COLORONCOLOR STRETCH_HALFTONE Same as HALFTONE STRETCH_ORSCANS Same as WHITEONBLACK WHITEONBLACK Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves white pixels at the expense of black pixels
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int setStretchBltMode( int mode ); #endif /* \details Copies the color data for a rectangle of pixels in a DIB, JPEG, or PNG image to the specified destination rectangle. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param DestWidth [in] Width of the destination rectangle. \param DestHeight [in] Height of the destination rectangle. \param xSrc [in] X coordinate of the source rectangle in the image (in pixels). \param ySrc [in] Y coordinate of the source rectangle in the image (in pixels). \param SrcWidth [in] The width of the source rectangle in the image (in pixels). \param SrcHeight [in] The height of the source rectangle in the image (in pixels). \param lpBits [in] A pointer to the image bits. \param lpbmi [in] Contains information about the DIB. \param iUsage [in] Indicates how colors are stored in the lpbmi (as array of 16-bit indexes into the logical palette, or as direct RGB values). \param rop [in] Raster-operation code that specifies how the source pixels, the destination device context's current brush, and the destination pixels are to be combined to form the new image. \returns Number of scan lines copied if the method executes successfully, 0 if no scan lines are copied or the method fails. \remarks If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int stretchDIBits( int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, const void* lpBits, const BITMAPINFO* lpbmi, UINT iUsage, DWORD rop ); /* \details Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param wDest [in] Width of the destination rectangle. \param hDest [in] Height of the destination rectangle. \param hdcSrc [in] Handle to the source device context. \param xSrc [in] X coordinate of the source rectangle in the image. \param ySrc [in] Y coordinate of the source rectangle in the image. \param wSrc [in] The width of the source rectangle in the image. \param hSrc [in] The height of the source rectangle in the image. \param rop [in] Raster-operation code that specifies how the colors in output operations that involve a brush, a source bitmap, and a destination bitmap are combined to form the new image. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool stretchBlt( int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop ); /* \details Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the target device context into a destination device context. \param x [in] X coordinate of the upper-left corner of the destination rectangle. \param y [in] Y coordinate of the upper-left corner of the destination rectangle. \param cx [in] Width of the source and destination rectangles. \param cy [in] Height of the source and destination rectangles. \param hdcSrc [in] Handle to the source device context. \param x1 [in] X coordinate of the source rectangle in the image. \param y1 [in] Y coordinate of the source rectangle in the image. \param rop [in] Raster-operation codes that specifies how the colors from source rectangle are combined with colors from destination rectangle to form the new color data. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool bitBlt( int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop ); /* \details Combines the color data for the source and destination bitmaps using the specified mask and raster operation. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param width [in] Width of the destination rectangle and source bitmap. \param height [in] Height of the destination rectangle and source bitmap. \param hdcSrc [in] Handle to the source device context. \param xSrc [in] X coordinate of the upper-left corner of the source bitmap. \param ySrc [in] Y coordinate of the upper-left corner of the source bitmap. \param hbmMask [in] Handle to the monochrome mask bitmap combined with the color bitmap in the source device context. \param xMask [in] Horizontal pixel offset for the mask bitmap. \param yMask [in] Vertical pixel offset for the mask bitmap. \param rop [in] Raster-operation codes that controls the combination of source and destination data. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool maskBlt( int xDest, int yDest, int width, int height, HDC hdcSrc, int xSrc, int ySrc, HBITMAP hbmMask, int xMask, int yMask, DWORD rop ); /* \details Creates a DIB section to which applications can write directly. \param pbmi [in] Pointer to a structure that specifies various attributes of the DIB. \param usage [in] Indicates how colors are stored (as array of 16-bit indexes into the logical palette, or as direct RGB values). \param refl [in] Bytes reflector to reflect data changes from target device context to the mirror device context. \param hSection [in] (Optional) A handle to a file-mapping object that the function will use to create the DIB. \param offset [in] Offset from the beginning of the file-mapping object that indicates where bitmap bit values storage begins. If hSection is NULL, this parameter can be ignored. \returns Value that is a handle to the newly created DIB. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ HBITMAP createDIBSection( const BITMAPINFO* pbmi, UINT usage, OdExGiGDIBytesReflector& refl, HANDLE hSection, DWORD offset ); /* \details Sets the pixels in the specified rectangle on the device that is associated with the destination device context using color data from a DIB, JPEG, or PNG image. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param w [in] Width of the image. \param h [in] Height of the image. \param xSrc [in] X coordinate of the lower-left corner of the image. \param ySrc [in] Y coordinate of the lower-left corner of the image. \param StartScan [in] The starting scan line in the image. \param cLines [in] The number of DIB scan lines contained in the data array of the DIB section of the target device context. \param refl [in] Bytes reflector to reflect data changes from target device context to the mirror device context. \param lpbmi [in] Structure that contains information about the DIB. \param ColorUse [in] Indicates how colors are stored (as array of 16-bit indexes into the logical palette, or as direct RGB values). \returns Number of scan lines set if the method executes successfully, 0 if no scan lines are set or the method fails. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ int setDIBitsToDevice( int xDest, int yDest, DWORD w, DWORD h, int xSrc, int ySrc, UINT StartScan, UINT cLines, const OdExGiGDIBytesReflector& refl, const BITMAPINFO* lpbmi, UINT ColorUse ); #ifndef _WIN32_WCE /* \details Displays the picture stored in the specified enhanced-format metafile. \param hmf [in] Handle to the enhanced metafile. \param lprect [in] Structure that contains the coordinates of the bounding rectangle used to display the picture. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool playEnhMetaFile( HENHMETAFILE hmf, const RECT* lprect ); #endif //Additional geometry methods /* \details Draws a triangle. \param apt [in] Pointer to an array of points. \returns true if the method executes successfully, false otherwise. */ bool triangle( const POINT* apt ); //Transparency support /* \details Sets the alpha channel value and color. \param alpha [in] Alpha value. \param color [in] Alpha color. */ void setAlpha( OdUInt8 alpha, COLORREF color ) { m_alpha = alpha; SETBIT( m_flags, kAlphaMode, alpha < 255 ); m_color = color; } /** \details Retrives color value. \returns Color value. */ COLORREF color() const { return m_color; } /* \details Returns alpha value. \returns Alpha value. */ OdUInt8 getAlpha() const { return m_alpha; } /* \details Checks whether the transparency is supported. \returns true if alpha is supported, false otherwise. */ inline bool isAlphaMode() const { return GETBIT( m_flags, kAlphaMode ) && GETBIT( m_flags, kAlphaTrp ); } /* \details Gets a pixel color considering alpha support. \param x [in] X coordinate of the pixel. \param y [in] Y coordinate of the pixel. \returns Pixel color value of the specified point if the method executes successfully, or returns invalid color CLR_INVALID (0xFFFFFFFF) otherwise. */ COLORREF getPixelColorForAlpha( int x, int y ); /* \details Draws a line from the current position up to the specified point specified with the alpha support. \param x [in] X coordinate of the line endpoint. \param y [in] Y coordinate of the line endpoint. \returns true if the line is successfully drawn, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaLineTo( int x, int y ); /* \details Draws a line from one point to another point with the alpha support. \param x1 [in] X coordinate of the first line point. \param y1 [in] Y coordinate of the first line point. \param x2 [in] X coordinate of the second line point. \param y2 [in] Y coordinate of the second line point. \param bCheckWidth [in] Flag that specifies whether to take into account current pen width. \returns true if the line is successfully drawn, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaLine( int x1, int y1, int x2, int y2, bool bCheckWidth = true ); /* \details Draws a line from x1 to x2 with fixed y coordinate. \param x1 [in] X coordinate of the first line point. \param y1 [in] Y coordinate of the first line point. \param y [in] X coordinate of the second line point. \param nRow [in] Number of line in the triangle. Not used. \returns true if the line is successfully drawn, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaTriangleLine( int x1, int x2, int y, OdUInt32 nRow ); bool alphaTriangleLineMirror( int x1, int x2, int y, OdUInt32 nRow ); /* \details Sets a color of a pixel taking into account alpha channel. \param x [in] X coordinate of the pixel. \param y [in] Y coordinate of the pixel. \param color [in] Pixel color. \returns RGB value of color that is actually drawn. If this method fails it returns -1. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ COLORREF alphaSetPixel( int x, int y, COLORREF color ); /* \details Sets a color of a pixel in the memory bitmap taking into account alpha channel. \param x [in] X coordinate of the pixel. \param y [in] Y coordinate of the pixel. \param color [in] Pixel color. \returns True if and only if color pixel specified. If this method fails it returns false. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaSetPixelMirror( int x, int y, COLORREF color ); /* \details Draws a triangle taking into account alpha channel. \param apt [in] Pointer to an array of points. \returns true if the method executes successfully, false otherwise. */ bool alphaTriangle( const POINT* apt ); /* \details Draws a polyline taking into account alpha channel. \param apt [in] Pointer to a array of points. \param cpt [in] Count of points in the array. Must be greater than or equal to 2. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaPolyline( const POINT* apt, int cpt ); /* \details Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. This method takes into account alpha channel. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param wDest [in] Width of the destination rectangle. \param hDest [in] Height of the destination rectangle. \param hdcSrc [in] Handle to the source device context. \param xSrc [in] X coordinate of the source rectangle in the image. \param ySrc [in] Y coordinate of the source rectangle in the image. \param wSrc [in] The width of the source rectangle in the image. \param hSrc [in] The height of the source rectangle in the image. \param rop [in] Raster-operation code that specifies how the colors in output operations that involve a brush, a source bitmap, and a destination bitmap are combined to form the new image. \returns true if the method executes successfully, false otherwise. \remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaStretchBlt( int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop ); /* \details Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. This method takes into account alpha channel. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param wDest [in] Width of the destination rectangle. \param hDest [in] Height of the destination rectangle. \param pBits [in] Pointer to image data. \param w [in] Image width. \param format [in] Image format. \param bpp [in] Image depth (bits per pixel). \param xSrc [in] X coordinate of the source rectangle in the image. \param ySrc [in] Y coordinate of the source rectangle in the image. \param wSrc [in] The width of the source rectangle in the image. \param hSrc [in] The height of the source rectangle in the image. \param rop [in] Raster-operation code that specifies how the colors in output operations that involve a brush, a source bitmap, and a destination bitmap are combined to form the new image. \returns true if the method executes successfully, false otherwise. \remarks The 'format' parameter can be one of the following: NameDescription BI_RGB Uncompressed bitmap in RGB format BI_RLE8 An RGB format that uses run-length encoding (RLE) compression for bitmaps with 8 bits per pixel BI_RLE4 An RGB format that uses RLE compression for bitmaps with 4 bits per pixel BI_BITFIELDS The bitmap is not compressed, and the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel BI_JPEG The image is a JPEG image. This value should only be used in certain bitmap operations, such as JPEG pass-through BI_PNG The image is a JPEG image. This value should only be used in certain bitmap operations, such as PNG/JPEG pass-through
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool alphaStretchBits( int xDest, int yDest, int wDest, int hDest, const OdUInt8* pBits, int w, OdUInt8 format, OdUInt8 bpp, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop, bool fromDIB = false ); bool alphaStretchBitsMirror( int xDest, int yDest, int wDest, int hDest, const OdUInt8* pBits, int w, OdUInt8 format, OdUInt8 bpp, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop, bool fromDIB = false ); /* \details Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. This method is the same as stretchBits(), but instead of targetDC it uses MemeryDC, i.e. it works in MirrorMode. \param xDest [in] X coordinate of the upper-left corner of the destination rectangle. \param yDest [in] Y coordinate of the upper-left corner of the destination rectangle. \param wDest [in] Width of the destination rectangle. \param hDest [in] Height of the destination rectangle. \param pBits [in] Pointer to image data. \param w [in] Image width. \param format [in] Image format. \param bpp [in] Image depth (bits per pixel). \param xSrc [in] X coordinate of the source rectangle in the image. \param ySrc [in] Y coordinate of the source rectangle in the image. \param wSrc [in] The width of the source rectangle in the image. \param hSrc [in] The height of the source rectangle in the image. \param rop [in] Raster-operation code that specifies how the colors in output operations that involve a brush, a source bitmap, and a destination bitmap are combined to form the new image. \returns true if the method executes successfully, false otherwise. \remarks The 'format' parameter can be one of the following: NameDescription BI_RGB Uncompressed bitmap in RGB format BI_RLE8 An RGB format that uses run-length encoding (RLE) compression for bitmaps with 8 bits per pixel BI_RLE4 An RGB format that uses RLE compression for bitmaps with 4 bits per pixel BI_BITFIELDS The bitmap is not compressed, and the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel BI_JPEG The image is a JPEG image. This value should only be used in certain bitmap operations, such as JPEG pass-through BI_PNG The image is a JPEG image. This value should only be used in certain bitmap operations, such as PNG/JPEG pass-through
\remarks For more information, see corresponding function in the official Microsoft documentation for the wingdi.h header. */ bool stretchBitsMemDC( int xDest, int yDest, int wDest, int hDest, const OdUInt8* pBits, int w, OdUInt8 format, OdUInt8 bpp, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop ); struct RasterTrpContext { HDC m_hDc; HBITMAP m_hBitmap, m_hPrevBitmap; }; RasterTrpContext *beginTransparentRasterProc(int xDest, int yDest, int wDest, int hDest); void endTransparentRasterProc(RasterTrpContext *pCtx, int xDest, int yDest, int wDest, int hDest); /* \details Clears all presented points. */ void clearPresentedPoints() { m_presentedPoints.clear(); } ///////DEBUG STUFF /* void SaveMemoryBitmap( const OdString& file ); */ }; #include "TD_PackPop.h" #endif //EXGI_GDI_DC