CartoType C++ API 8.8-7-gb35e4dc71
for Windows, Linux, Qt and other platforms supporting C++ development
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CartoTypeCore::GraphicsContext Class Referenceabstract

#include <cartotype_graphics_context.h>

Public Member Functions

 GraphicsContext (std::shared_ptr< CEngine > aEngine, const Rect &aBounds, std::unique_ptr< Bitmap > aBitmap)
 
virtual DrawResult DrawBitmap (const BitmapView &aBitmap, const Point &aTopLeft)=0
 
virtual DrawResult DrawShape (const MPath &aPath)=0
 
virtual DrawResult DrawTexture (const Texture &aTexture, const PointFP &aTopLeft, const AffineTransform &aTransform)=0
 
virtual void Clear ()=0
 
virtual BitmapViewBitmap ()
 
virtual DrawResult DrawRect (const Rect &aRect)
 
virtual bool TransformsPoints ()
 
virtual DrawResult Transform2D (PointFP &aPoint, int32_t aFractionalBits)
 
virtual DrawResult Transform3D (Point3FP &aPoint)
 
virtual void InverseTransform2D (PointFP &aPoint, int32_t aFractionalBits)
 
virtual bool EnableTransform (bool aEnable)
 
virtual Rect UntransformedBounds ()
 
virtual DrawResult DrawStroke (const MPath &aPath, const AffineTransform *aTransform=nullptr, bool aClip=false)
 
virtual void SetGlow (Color aColor, double aWidth, const PointFP &aOffset)
 
virtual void GetGlow (Color &aColor, double &aWidth, PointFP &aOffset)
 
virtual DrawResult DrawBitmapMonochrome (const BitmapView &aBitmap, const Point &aTopLeft)
 
DrawResult DrawShapeAndStroke (const MPath &aPath, const Paint &aStrokePaint, const AffineTransform *aTransform=nullptr)
 
void SetClip (const Rect &aClip)
 
void SetColor (Color aColor)
 
void SetPaintServer (std::shared_ptr< PaintServer > aPaintServer)
 
void SetPaint (const Paint &aPaint)
 
void SetAlpha (int32_t aAlpha)
 
void SetTextureMask (Color aColor)
 
void SetParam (GraphicsParam &aParam)
 
void SetPen (const CircularPen &aPen)
 
DrawResult Transform (Point &aPoint, int32_t aFractionalBits)
 
void SwapBitmap (std::unique_ptr< CartoTypeCore::Bitmap > &aBitmap)
 
std::shared_ptr< CEngine > Engine ()
 
const RectClip () const
 
const auto & Paint () const
 
CartoTypeCore::Color Color () const
 
int32_t Alpha () const
 
const RectBounds () const
 
const CircularPenPen () const
 
void SetDashArray (std::shared_ptr< DashArray > aDashArray)
 
std::shared_ptr< CartoTypeCore::DashArrayDashArray () const
 
const GraphicsParamParam () const
 

Static Public Member Functions

static uint8_t MultiplyIntensities (int aIntensity1, int aIntensity2)
 
static uint8_t AlphaBlend (int aForeground, int aBackground, int aAlpha)
 

Protected Member Functions

DrawResult DrawDashedStroke (const MPath &aPath, const AffineTransform *aTransform)
 

Protected Attributes

std::shared_ptr< CEngine > iEngine
 
GraphicsParam iParam
 
Rect iBounds
 
int32_t iChangeFlags = KAllChanged
 
std::unique_ptr< CartoTypeCore::BitmapiBitmap
 

Static Protected Attributes

static constexpr int32_t KClipChanged = 1
 
static constexpr int32_t KPaintChanged = 2
 
static constexpr int32_t KGlowColorChanged = 4
 
static constexpr int32_t KTextureMaskChanged = 8
 
static constexpr int32_t KAllChanged = -1
 

Detailed Description

The base graphics context class. A graphics context draws to a raster drawing surface with square pixels.

Constructor & Destructor Documentation

◆ GraphicsContext()

CartoTypeCore::GraphicsContext::GraphicsContext ( std::shared_ptr< CEngine >  aEngine,
const Rect aBounds,
std::unique_ptr< Bitmap aBitmap 
)

Constructs a graphics context to draw into aBounds.

Member Function Documentation

◆ Alpha()

int32_t CartoTypeCore::GraphicsContext::Alpha ( ) const
inline

Returns the current alpha (opacity) level as a number in the range 0 ... 255.

◆ AlphaBlend()

static uint8_t CartoTypeCore::GraphicsContext::AlphaBlend ( int  aForeground,
int  aBackground,
int  aAlpha 
)
inlinestatic

Blends aForeground and aBackground in the proportion aAlpha. All three numbers are intensities in the range 0...255.

◆ Bitmap()

BitmapView * CartoTypeCore::GraphicsContext::Bitmap ( )
virtual

Returns a pointer to the bitmap, if any.

Returns the bitmap drawn to by the graphics context, if any. If the graphics context does not draw to a bitmap, this function returns nullptr.

◆ Bounds()

const Rect & CartoTypeCore::GraphicsContext::Bounds ( ) const
inline

Return the rectangle that the graphics context draws to if no clipping is done.

◆ Clear()

virtual void CartoTypeCore::GraphicsContext::Clear ( )
pure virtual

Clears the drawing area to transparent black. If colors are not stored sets all pixels to zero intensity. If transparency levels are not stored sets all pixels to black.

◆ Clip()

const Rect & CartoTypeCore::GraphicsContext::Clip ( ) const
inline

Returns the clipping rectangle.

◆ Color()

CartoTypeCore::Color CartoTypeCore::GraphicsContext::Color ( ) const
inline

Returns the current color as an RGBA value including the alpha channel.

◆ DashArray()

std::shared_ptr< CartoTypeCore::DashArray > CartoTypeCore::GraphicsContext::DashArray ( ) const
inline

Returns the current dash array.

◆ DrawBitmap()

virtual DrawResult CartoTypeCore::GraphicsContext::DrawBitmap ( const BitmapView aBitmap,
const Point aTopLeft 
)
pure virtual

Draws a bitmap. If the bitmap has no color information, uses the current color. Combines any alpha information from the bitmap with the current alpha level. The coordinates are whole pixels.

◆ DrawBitmapMonochrome()

DrawResult CartoTypeCore::GraphicsContext::DrawBitmapMonochrome ( const BitmapView aBitmap,
const Point aTopLeft 
)
virtual

Draws a colored bitmap in monochrome using the current color to colorise it. The default implementation draws the bitmap normally.

◆ DrawDashedStroke()

DrawResult CartoTypeCore::GraphicsContext::DrawDashedStroke ( const MPath aPath,
const AffineTransform aTransform 
)
protected

Draws a dashed stroke using the current dash array, optionally transforming it by aTransform.

◆ DrawRect()

DrawResult CartoTypeCore::GraphicsContext::DrawRect ( const Rect aRect)
virtual

Draws a filled rectangle in the current color. The coordinates are whole pixels.

◆ DrawShape()

virtual DrawResult CartoTypeCore::GraphicsContext::DrawShape ( const MPath aPath)
pure virtual

Draws a filled shape in the current color. The coordinates are in 64ths of pixels.

◆ DrawShapeAndStroke()

DrawResult CartoTypeCore::GraphicsContext::DrawShapeAndStroke ( const MPath aPath,
const Paint aStrokePaint,
const AffineTransform aTransform = nullptr 
)

Fills and outlines a shape. The path coordinates are 64ths of pixels. The shape is filled if the current paint is non-null, and outlined if aStrokePaint is non-null. Optionally apply a transform to the shape and the stroke envelope. The offsets in aTransform are whole pixels.

◆ DrawStroke()

DrawResult CartoTypeCore::GraphicsContext::DrawStroke ( const MPath aPath,
const AffineTransform aTransform = nullptr,
bool  aClip = false 
)
virtual

Draws a stroke using the current circular pen.

The path coordinates are 64ths of pixels.

Optionally applies a transform to the stroke envelope before drawing it. The offsets in aTransform are whole pixels.

◆ DrawTexture()

DrawResult CartoTypeCore::GraphicsContext::DrawTexture ( const Texture aTexture,
const PointFP aTopLeft,
const AffineTransform aTransform 
)
pure virtual

Draws a texture at aTopLeft, transforming it by aTransform.

Draws a texture at aTopLeft, transforming it by aTransform. The base implementation throws KErrorUnimplemented.

◆ EnableTransform()

bool CartoTypeCore::GraphicsContext::EnableTransform ( bool  aEnable)
virtual

Enables or disables any transformation applied by the graphics context. Returns the previous state. The base implementation does nothing and returns false.

◆ Engine()

std::shared_ptr< CEngine > CartoTypeCore::GraphicsContext::Engine ( )
inline

Returns a pointer to the graphics engine.

◆ GetGlow()

void CartoTypeCore::GraphicsContext::GetGlow ( CartoTypeCore::Color aColor,
double &  aWidth,
PointFP aOffset 
)
virtual

Gets the current glow parameters.

◆ InverseTransform2D()

void CartoTypeCore::GraphicsContext::InverseTransform2D ( PointFP aPoint,
int32_t  aFractionalBits 
)
virtual

Applies the inverse of the graphics context's current transformation to a point. See GraphicsContext::Transform function for details.

◆ MultiplyIntensities()

static uint8_t CartoTypeCore::GraphicsContext::MultiplyIntensities ( int  aIntensity1,
int  aIntensity2 
)
inlinestatic

Multiplies two intensities, treated as fractions in the range 0...255.

◆ Paint()

const auto & CartoTypeCore::GraphicsContext::Paint ( ) const
inline

Returns the current paint.

◆ Param()

const GraphicsParam & CartoTypeCore::GraphicsContext::Param ( ) const
inline

Returns the current graphics parameters.

◆ Pen()

const CircularPen & CartoTypeCore::GraphicsContext::Pen ( ) const
inline

Returns the pen used for drawing strokes.

◆ SetAlpha()

void CartoTypeCore::GraphicsContext::SetAlpha ( int32_t  aAlpha)

Sets the alpha (transparency) level, where 0 = transparent and 255 = opaque.

◆ SetClip()

void CartoTypeCore::GraphicsContext::SetClip ( const Rect aClip)

Sets the clip rectangle.

◆ SetColor()

void CartoTypeCore::GraphicsContext::SetColor ( CartoTypeCore::Color  aColor)

Sets the color used for painting and sets the paint server to null.

◆ SetDashArray()

void CartoTypeCore::GraphicsContext::SetDashArray ( std::shared_ptr< DashArray aDashArray)
inline

Sets the array of dash and gap sizes used for dashed strokes.

◆ SetGlow()

void CartoTypeCore::GraphicsContext::SetGlow ( CartoTypeCore::Color  aColor,
double  aWidth,
const PointFP aOffset 
)
virtual

Sets the current glow parameters. Bitmaps are drawn with a glowing border if the glow color is not fully transparent and the glow width is greater than zero. The default implementation does nothing.

◆ SetPaint()

void CartoTypeCore::GraphicsContext::SetPaint ( const Paint aPaint)

Sets the color and the paint server.

◆ SetPaintServer()

void CartoTypeCore::GraphicsContext::SetPaintServer ( std::shared_ptr< PaintServer aPaintServer)

Sets the paint server. A value of null tells the graphics context not to use a paint server but to use the current color.

◆ SetParam()

void CartoTypeCore::GraphicsContext::SetParam ( GraphicsParam aParam)

Sets the graphics parameters to the values in aParam.

◆ SetPen()

void CartoTypeCore::GraphicsContext::SetPen ( const CircularPen aPen)

Sets the pen used for drawing strokes.

◆ SetTextureMask()

void CartoTypeCore::GraphicsContext::SetTextureMask ( CartoTypeCore::Color  aColor)

Sets the texture mask color: the color that prevents texture pixels from being drawn in unwanted areas like the sea.

◆ SwapBitmap()

void CartoTypeCore::GraphicsContext::SwapBitmap ( std::unique_ptr< CartoTypeCore::Bitmap > &  aBitmap)
inline

Swaps the bitmap with another one.

◆ Transform()

DrawResult CartoTypeCore::GraphicsContext::Transform ( Point aPoint,
int32_t  aFractionalBits 
)

If this GC transforms points, applies the its current transformation to an integer point.

◆ Transform2D()

DrawResult CartoTypeCore::GraphicsContext::Transform2D ( PointFP aPoint,
int32_t  aFractionalBits 
)
virtual

Applies the graphics context's current transformation to a point. Returns false if the transformation fails because of range or other issues.

Graphics contexts that provide a non-identity overriding implementation of this function must also override TransformsPoints to return true. The base implementation is identity and thus does nothing. Although the transform does not change the point's representation, the number of fractional bits must be supplied so that the transform can use actual pixels consistently, as in a perpective transform.

◆ Transform3D()

DrawResult CartoTypeCore::GraphicsContext::Transform3D ( Point3FP aPoint)
virtual

Applies the graphics context's current transformation to a 3D point.

Graphics contexts, like the perspective GC, that provide a non-identity overriding implementation of this function, must also override TransformsPoints to return true. The base implementation is identity and thus does nothing. The units of aPoint are whole pixels.

◆ TransformsPoints()

bool CartoTypeCore::GraphicsContext::TransformsPoints ( )
virtual

Returns true if the GC applies a further transformation to points before drawing them, as for example the perspective transformation. The base implementation returns false.

◆ UntransformedBounds()

Rect CartoTypeCore::GraphicsContext::UntransformedBounds ( )
virtual

Returns the bounds of the display plane before any transformaton applied by it by the GC. The base implementation returns the ordinary bounds.

Member Data Documentation

◆ iBitmap

std::unique_ptr<CartoTypeCore::Bitmap> CartoTypeCore::GraphicsContext::iBitmap
protected

If non-null, the bitmap owned by the graphics context.

◆ iBounds

Rect CartoTypeCore::GraphicsContext::iBounds
protected

The bounds, in pixels, of the device drawn into.

◆ iChangeFlags

int32_t CartoTypeCore::GraphicsContext::iChangeFlags = KAllChanged
protected

Flags that are set when graphics parameters are changed, allowing derived classes to synchronize their internal states if necessary.

◆ iEngine

std::shared_ptr<CEngine> CartoTypeCore::GraphicsContext::iEngine
protected

The engine object, which provides the shape rendering engines and other shared resources.

◆ iParam

GraphicsParam CartoTypeCore::GraphicsContext::iParam
protected

The drawing parameters such as the color and clip rectangle.

◆ KAllChanged

constexpr int32_t CartoTypeCore::GraphicsContext::KAllChanged = -1
staticconstexprprotected

A flag used in iChangeFlags: all graphics parameters have changed; the internal state must be completely initialised.

◆ KClipChanged

constexpr int32_t CartoTypeCore::GraphicsContext::KClipChanged = 1
staticconstexprprotected

A flag used in iChangeFlags: the clip rectangle has changed.

◆ KGlowColorChanged

constexpr int32_t CartoTypeCore::GraphicsContext::KGlowColorChanged = 4
staticconstexprprotected

A flag used in iChangeFlags: the glow color, if any, has changed.

◆ KPaintChanged

constexpr int32_t CartoTypeCore::GraphicsContext::KPaintChanged = 2
staticconstexprprotected

A flag used in iChangeFlags: the paint has changed.

◆ KTextureMaskChanged

constexpr int32_t CartoTypeCore::GraphicsContext::KTextureMaskChanged = 8
staticconstexprprotected

A flag used in iChangeFlags: the texture mask has changed.


The documentation for this class was generated from the following files: