related tdf#147583 sw find: fix backwards search for string at end of para
[LibreOffice.git] / drawinglayer / README.md
blob04ebcadf0b17291a6ec8c0b5b681743c103355af
1 # Drawing API
3 Drawing API that can specify what to draw via a kind of display list.
5 Example of the DrawingLayer use is eg. in `svx/source/xoutdev/xtabhtch.cxx:121`.
6 A stripped down version with extended comments:
8      // Create a hatch primitive (here a rectangle that will be filled with
9      // the appropriate hatching, but has no border).
10      // This will not draw it yet; it's so far only constructed to add it to a
11      // display list later.
12      const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
13          new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(...));
15      // Create a rectangle around the hatch, to give it a border.
16      const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
17          new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(...));
19      // Here we want to render to a virtual device (to later obtain the bitmap
20      // out of that), so prepare it.
21      VirtualDevice aVirtualDevice;
23      // Create processor and draw primitives, to get it ready for rendering.
24      std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(
25          drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(...));
27      // Fill-in the display list.
28      drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
30      aSequence[0] = aHatchPrimitive;
31      aSequence[1] = aBlackRectanglePrimitive;
33      // Render it to the virtual device.
34      pProcessor2D->process(aSequence);
35      pProcessor2D.reset();
37      // Obtain the bitmap that was rendered from the virtual device, to re-use
38      // it in the widget.
39      aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());
41 ## DrawingLayer Glossary
43 Primitives - classes that represent what should be drawn.  It holds the data
44 what to draw, but does not contain any kind of the rendering.  Some of the
45 primitives are 'Basic primitives', that are primitives that cannot be
46 decomposed.  The rest of the primitives can be decomposed to the basic
47 primitives.
49 Decomposition - a way how to break down the more complicated primitives into
50 the basic primitives, and represent them via them; this logically makes the
51 plain `Primitive2DSequence` display list a hierarchy.
52 Eg. `PolygonMarkerPrimitive2D` can be decomposed to 2 hairlines
53 `PolyPolygonHairlinePrimitive2D`'s, each with different color.
55 Processor - a class that goes through the hierarchy of the Primitives, and
56 renders it some way.  Various processors, like `VclPixelProcessor2D` (renders to
57 the screen), `VclMetafileProcessor2D` (renders to the VCL metafile, eg. for
58 printing), etc.
60 ## How to Implement a New Primitive ("Something New to Draw")
62 * Create an ancestor of `BasePrimitive2D`
63   (or of its ancestor if it fits the purpose better)
65   * Assign it an ID [in `drawinglayer_primitivetypes2d.hxx`]
67   * Implement its decomposition
68     [`virtual Primitive2DSequence create2DDecomposition(...)`]
70 * Extend the (various) processor(s)
71   If you need more than relying on just the decomposition
73 ## Where is DrawingLayer Used
75 * `SdrObject`(s) (rectangles, Circles, predefined shapes etc.)
77 * Selections
79 * Various smaller cases to 'just draw something'
81   * Draw to a virtual device, and use the resulting bitmap (like the example
82     above)
84 * Custom widgets (like the Header / Footer indicator button)