Lomse library. API documentation
0.30.0
|
#include <lomse_drawer.h>
Drawer is an abstract base class for any drawer object. A drawer is responsible for transforming drawing commands into something understandable by the underlying rendering engine (e.g.: a bitmap, svg file, paths, etc.), to display the sheet music.
The Drawer class is equivalent to the drawing interfaces present the operating systems' graphics libraries, for example macOS' “Quartz”, Linux X Window System's “Xlib/XCB” or the Microsoft Windows API “Device Context” (DC) that is part of the “Graphics Device Interface” (GDI).
As Lomse aims to be platform independent, it does not use any platform specific graphics interface. Instead it was decided to create an abstract interface class: Drawer. This solution allows any user application to implement its own drawer classes and do all drawing natively without having to use the BitmapDrawer class implemented by Lomse.
The interface of Drawer class mimics SVG commands.
Public Member Functions | |
Drawer (LibraryScope &libraryScope) | |
virtual | ~Drawer () |
SVG path commands | |
Methods to define a path and all its commands. | |
virtual void | begin_path ()=0 |
virtual void | end_path ()=0 |
virtual void | close_path ()=0 |
virtual void | add_path (VertexSource &vs, unsigned path_id=0, bool solid_path=true)=0 |
virtual void | move_to (double x, double y)=0 |
virtual void | move_to_rel (double x, double y)=0 |
virtual void | line_to (double x, double y)=0 |
virtual void | line_to_rel (double x, double y)=0 |
virtual void | hline_to (double x)=0 |
virtual void | hline_to_rel (double x)=0 |
virtual void | vline_to (double y)=0 |
virtual void | vline_to_rel (double y)=0 |
virtual void | quadratic_bezier (double x1, double y1, double x, double y)=0 |
virtual void | quadratic_bezier_rel (double x1, double y1, double x, double y)=0 |
virtual void | quadratic_bezier (double x, double y)=0 |
virtual void | quadratic_bezier_rel (double x, double y)=0 |
virtual void | cubic_bezier (double x1, double y1, double x2, double y2, double x, double y)=0 |
virtual void | cubic_bezier_rel (double x1, double y1, double x2, double y2, double x, double y)=0 |
virtual void | cubic_bezier (double x2, double y2, double x, double y)=0 |
virtual void | cubic_bezier_rel (double x2, double y2, double x, double y)=0 |
SVG basic shapes commands | |
Methods to draw elements defined by some combination of straight lines and curves. Specifically: ‘circle’, ‘line’, ‘path’, ‘polygon’, and ‘rect’. Using these methods requires first to invoque begin_path(), as well as to define the desired attributes by invoking attribute setting methods (e.g. fill(), stroke(), ...). And finally closing the path close_path(). | |
virtual void | rect (UPoint pos, USize size, LUnits radius)=0 |
virtual void | circle (LUnits xCenter, LUnits yCenter, LUnits radius)=0 |
virtual void | line (LUnits x1, LUnits y1, LUnits x2, LUnits y2, LUnits width, ELineEdge nEdge=k_edge_normal)=0 |
virtual void | polygon (int n, UPoint points[])=0 |
virtual void | line_with_markers (UPoint start, UPoint end, LUnits width, ELineCap startCap, ELineCap endCap)=0 |
Attribute setting methods | |
Define the attributes for current open path. | |
virtual void | fill (Color color)=0 |
virtual void | fill_none ()=0 |
virtual void | stroke (Color color)=0 |
virtual void | stroke_none ()=0 |
virtual void | stroke_width (double w)=0 |
virtual void | gradient_color (Color c1, Color c2, double start, double stop)=0 |
virtual void | gradient_color (Color c1, double start, double stop)=0 |
virtual void | fill_linear_gradient (LUnits x1, LUnits y1, LUnits x2, LUnits y2)=0 |
Text redering methods | |
Are somehow equivalent to the "<text>" SVG element. | |
virtual bool | select_font (const std::string &language, const std::string &fontFile, const std::string &fontName, double height, bool fBold=false, bool fItalic=false)=0 |
virtual void | set_text_color (Color color) |
virtual int | draw_text (double x, double y, const std::string &str)=0 |
virtual int | draw_text (double x, double y, const wstring &str)=0 |
virtual void | draw_glyph (double x, double y, unsigned int ch)=0 |
virtual void | draw_glyph_rotated (double x, double y, unsigned int ch, double rotation)=0 |
Render a bitmap | |
virtual void | draw_bitmap (RenderingBuffer &bmap, bool hasAlpha, Pixels srcX1, Pixels srcY1, Pixels srcX2, Pixels srcY2, LUnits dstX1, LUnits dstY1, LUnits dstX2, LUnits dstY2, EResamplingQuality resamplingMode, double alpha=1.0)=0 |
Drawer settings | |
Methods to render a bitmap. They are somehow equivalent to the "image" SVG element. The only one currently used by Lomse is draw_bitmap() and is used when the Document includes some JPG or PNG image. | |
virtual void | set_shift (LUnits x, LUnits y)=0 |
virtual void | remove_shift ()=0 |
virtual void | render ()=0 |
virtual void | set_affine_transformation (TransAffine &transform)=0 |
virtual void | reset (Color bgcolor)=0 |
Device <--> model units conversion | |
In Lomse, there are two types of coordinates: those defined in the device space, that is, the Drawer space (e.g. pixels) and those defined in the model space, that is, real world units (tenths of one millimeter). | |
virtual void | device_point_to_model (double *x, double *y) const =0 |
virtual void | model_point_to_device (double *x, double *y) const =0 |
virtual LUnits | device_units_to_model (double value) const =0 |
virtual double | model_to_device_units (LUnits value) const =0 |
Shapes info | |
These methods serve to provide the Drawer with information about the shapes it is drawing. This information is normally irrelevant but in some cases (e.g.SVG) it can be incorporated into the output if desired. | |
virtual void | start_simple_notation (std::string UNUSED(id), std::string UNUSED(classname)) |
virtual void | start_composite_notation (std::string UNUSED(id), std::string UNUSED(classname)) |
virtual void | end_composite_notation () |
Viewport info | |
Viewport is a concept related to the View, not to the Drawer. But for some Drawer implementations, this information can be required. For instance, the Drawer can speed up rendition if it knows the area that is currently visible, so that it can ignore non-visible areas. Therefore, the View always informs the Drawer when any change in the viewport. Received coordinates are in device units (e.g. Pixels). | |
virtual void | new_viewport_origin (double x, double y) |
virtual void | new_viewport_size (double x, double y) |
Other methods | |
virtual bool | is_ready () const =0 |
virtual bool | accepts_id_class () const |
Drawer::Drawer | ( | LibraryScope & | libraryScope | ) |
Constructor.
libraryScope | The library Scope object associated to this instance of the Lomse library. Can be obtained with method LomseDoorway::get_library_scope(). |
|
inlinevirtual |
Destructor
|
inlinevirtual |
Returns true if the Drawer accepts 'id' and 'class' information
|
pure virtual |
Creates a new path with its commands and points provided by the "VertexSource" parameter. It is similar to SVG "path" element.
|
pure virtual |
Start a path. Equivalent to SVG start tag "<path ".
|
pure virtual |
Draw a circle based on a center point and a radius. It is equivalent to the "circle" SVG element.
|
pure virtual |
Close a sub-path. Equivalent to the "closepath" (Z and z) SVG command.
|
pure virtual |
Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. All points in absolute coordinates. It is equivalent to the "C" SVG path instruction.
|
pure virtual |
Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not an C, c, S or s, assume the first control point is coincident with the current point.) (x2,y2) is the second control point (i.e., the control point at the end of the curve). All points in absolute coordinates. It is equivalent to the "S" SVG path instruction.
|
pure virtual |
Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. All points in absolute coordinates. It is equivalent to the "c" SVG path instruction.
|
pure virtual |
Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not an C, c, S or s, assume the first control point is coincident with the current point.) (x2,y2) is the second control point (i.e., the control point at the end of the curve). All points in relative coordinates. It is equivalent to the "s" SVG path instruction.
|
pure virtual |
Convert a point in device coordinates (e.g. pixels) to model coordinates (real world units, tenths of one millimeter).
|
pure virtual |
Convert device units (e.g. pixels) to model units (real world units, tenths of one millimeter).
|
pure virtual |
Render part of a bitmap. It is somehow equivalent to the "image" SVG element.
bmap | The struct RenderingBuffer containing the pointer to the bitmap and its dimensions in pixels. |
hasAlpha | true when the bitmap has alpha channel information. |
srcX1,srcY1,srcX2,srcY2 | Top-left and bottom-right points of the source bitmap, in device units. |
dstX1,dstY1,dstX2,dstY2 | The destination top-left corner and bottom-right corner, in model units. |
resamplingMode | Value from enum EResamplingQuality that defines how resampling (if required) must be done. |
alpha | Transparency (alpha value: 1.0 opaque). |
This method is currently used by Lomse when the Document includes a JPG or PNG image.
|
pure virtual |
Render a character. This method is equivalent to providing the x,y attributes for the "<text>" SVG element and the string content for that element.
x,y | Destination point, in model coordinates (LUnits). |
ch | The character to render. |
|
pure virtual |
Render a character rotated. This method is equivalent to providing the x,y attributes for the "<text>" SVG element, the string content for that element and the rotation parameters for the affine transform.
x,y | Destination point, in model coordinates (LUnits). |
ch | The character to render. |
rotation | The rotation to apply, in radians. |
|
pure virtual |
Render text. This method is equivalent to providing the x,y attributes for the "<text>" SVG element and the string content for that element.
x,y | Destination point, in model coordinates (LUnits). |
str | The text to render. |
|
pure virtual |
Render text. This method is equivalent to providing the x,y attributes for the "<text>" SVG element and the string content for that element.
x,y | Destination point, in model coordinates (LUnits). |
str | The text to render. |
|
inlinevirtual |
This method is used to inform the Drawer that the drawing of a composite element has finished.
|
pure virtual |
Terminate a path. Equivalent to closing the SVG path element " />".
|
pure virtual |
Set the color to fill current open path. Color can have alpha value, if transparency is desired.
|
pure virtual |
Set the currently defined linear gradient to be used for filling current open path. These methods are used by Lomse as follows:
|
pure virtual |
Do not fill current open path.
|
pure virtual |
Define a linear gradient that can be used in current open path.
|
pure virtual |
Define a linear gradient that can be used in current open path.
|
pure virtual |
Horizontal line to (absolute coordinates) command. It is equivalent to the "H" SVG path instruction.
|
pure virtual |
Horizontal line to (relative coordinates) command. It is equivalent to the "h" SVG path instruction.
|
pure virtual |
Returns true if the Drawer is initialized and can be used.
|
pure virtual |
Draw a line segment that starts at one point and ends at another. It is equivalent to the "circle" SVG element.
|
pure virtual |
Line to (absolute coordinates) command. It is equivalent to the abs. "lineto" (L) SVG path instruction.
|
pure virtual |
Line to (relative coordinates) command. It is equivalent to the rel. "lineto" (l) SVG path instruction.
|
pure virtual |
SVG line with start/end markers. Absolute coordinates.
|
pure virtual |
Convert a point in model coordinates (real world units, tenths of one millimeter) to device coordinates (e.g. pixels).
|
pure virtual |
Convert model units (real world units, tenths of one millimeter) to device units (e.g. pixels).
|
pure virtual |
Move to (absolute coordinates) command. The effect is as if the "pen" were lifted and moved to a new location. It is equivalent to the abs. "moveto" (M) SVG path instruction.
|
pure virtual |
Move to (relative coordinates) command. The effect is as if the "pen" were lifted and moved to a new location. It is equivalent to the rel. "moveto" (m) SVG path instruction.
|
virtual |
Set a new origin for the viewport. Its size does not change. Received coordinates are in device units (e.g. Pixels).
|
virtual |
Chage the size of the viewport. Its origin is not affected. Received values are in device units (e.g. Pixels).
|
pure virtual |
Draw a closed shape consisting of a set of connected straight line segments. It is equivalent to the "polygon" SVG element.
|
pure virtual |
Draws a quadratic Bézier curve from the current point to (x,y) using (x1,y1) as the control point. All points in absolute coordinates. It is equivalent to the "Q" SVG path instruction.
|
pure virtual |
Draws a quadratic Bézier curve from the current point to (x,y). The control point is assumed to be the reflection of the control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not a Q, q, T or t, assume the control point is coincident with the current point.) All points in absolute coordinates. It is equivalent to the "T" SVG path instruction.
|
pure virtual |
Draws a quadratic Bézier curve from the current point to (x,y) using (x1,y1) as the control point. All points in relative coordinates. It is equivalent to the "q" SVG path instruction.
|
pure virtual |
Draws a quadratic Bézier curve from the current point to (x,y). The control point is assumed to be the reflection of the control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not a Q, q, T or t, assume the control point is coincident with the current point.) All points in relative coordinates. It is equivalent to the "t" SVG path instruction.
|
pure virtual |
Draw a rectangle which is axis-aligned with the current user coordinate system. Rounded rectangles can be achieved by setting a non-zero value for the radius parameter. It is equivalent to the "rect" SVG element.
|
pure virtual |
Remove the temporary shift defined in the set_shift() method.
|
pure virtual |
Do render currently defined paths.
|
pure virtual |
Set the background color and prepare to render a new image.
|
pure virtual |
Select the font to be used form now on in all text rendering methods. The parameters are equivalent to the attibutes in the "text" SVG element.
language | A language code drawn from ISO 639, optionally extended with a country code drawn from ISO 3166, as 'en-US'. It represents the default language for the texts to be rendered. If not specified "en" is assumed. |
fontFile | Filename (without path) for the font file to use. This parameter is deprecated and should not be used; it will normally be empty. |
fontName | The name of a font, as it is usually specified in the 'font-name' CCS property. But it must contain only one font name, without quotes, e.g.: "Times New Roman". It can be generic, e.g.: "sans". |
height | Desired font height, in points. |
fBold | true if the desired font weight is 'bold'. |
fItalic | true if the desired font style is 'italic'. |
The font file must be selected based on the values for all these parameters. If exact match is not possible it is expected than a substitution font be selected.
|
pure virtual |
Set the affine transformation matrix to use.
|
pure virtual |
Add a temporay shift to subsequent elements and paths created after invoking this method. It is a facility to avoid that classes using the drawer having to directly manipulate the affine matrix for some position adjustment.
|
virtual |
Define the font-color attribute to use from now on.
|
inlinevirtual |
This method is used to inform the Drawer that the drawing of a new composite element (that is, an element requiring several SVG commands) is going to start.
|
inlinevirtual |
This method is used to inform the Drawer that the drawing of a new simple element (that is, an element requiring just one SVG command) is going to start.
|
pure virtual |
Set the color to stroke current open path. Color can have alpha value, if transparency is desired.
|
pure virtual |
Do not stroke current open path
|
pure virtual |
Define the width (in model units, a tenth of one millimeter) of the line to stroke current open path.
|
pure virtual |
Vertical line to (absolute coordinates) command. It is equivalent to the "V" SVG path instruction.
|
pure virtual |
Vertical line to (relative coordinates) command. It is equivalent to the "v" SVG path instruction.