Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
build-drawing.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Build PDF drawing elements
4 *
5 * Authors:
6 * Martin Owens <doctormo@geek-2.com?
7 *
8 * Copyright (C) 2024 Authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef EXTENSION_INTERNAL_PDFOUTPUT_BUILD_DRAWING_H
14#define EXTENSION_INTERNAL_PDFOUTPUT_BUILD_DRAWING_H
15
16#include "build-document.h"
17
18class SPGroup;
19class SPImage;
20class SPShape;
21class SPText;
22class SPUse;
23
24namespace Inkscape::Text {
25class Layout;
26}
27
29
31{
32public:
33 DrawContext(Document &doc, capypdf::DrawContext ctx, bool soft_mask)
34 : _ctx{std::move(ctx)}
35 , _doc{doc}
36 , _soft_mask{soft_mask}
37 {}
38 ~DrawContext() = default;
39
40 void paint_item(SPItem const *item, Geom::Affine const &tr = Geom::identity(),
41 SPStyle const *context_style = nullptr);
42 void paint_item_group(SPGroup const *group, SPStyle const *context_style);
43 void paint_item_clone(SPUse const *use, SPStyle const *context_style);
44
45 void paint_group(CapyPDF_TransparencyGroupId child_id, SPStyle const *style = nullptr,
46 Geom::Affine const &tr = Geom::identity(),
47 std::optional<CapyPDF_TransparencyGroupId> soft_mask = {});
48 void paint_shape(SPShape const *shape, SPStyle const *context_style);
49 void paint_raster(SPImage const *image);
50 void paint_item_to_raster(SPItem const *item, Geom::Affine const &tr, double resolution, bool antialias);
51 void paint_text_layout(Text::Layout const &layout, SPStyle const *context_style);
52 void clip_text_layout(Text::Layout const &layout);
53
54 void start_ocg(CapyPDF_OptionalContentGroupId ocgid);
55 void end_ocg();
56
57 bool set_shape(SPShape const *shape);
58 bool set_shape_pathvector(Geom::PathVector const &pathv);
59 void set_clip_path(std::optional<Geom::PathVector> clip, SPStyle *style = nullptr);
60 void set_clip_rectangle(Geom::OptRect const &rect);
61
62 void set_paint_style(StyleMap const &map, SPStyle const *style, SPStyle const *context_style);
63
64 Document &get_document() { return _doc; }
65 std::optional<double> get_softmask(double opacity) const;
66
67protected:
68 friend class Document;
69
70 void set_matrix(Geom::Affine const &affine);
71 void transform(Geom::Affine const &affine);
72
73 capypdf::DrawContext _ctx;
75
76private:
77 void set_shape_path(Geom::Path const &path);
78 bool set_shape_rectangle(Geom::Rect const &rect);
79
80 bool _soft_mask = false;
81};
82
84{
85public:
86 GroupContext(Document &doc, Geom::OptRect const &clip, bool soft_mask = false);
87
88private:
89};
90
92{
93public:
94 ItemContext(Document &doc, SPItem const *item);
95
96 bool is_valid() const;
97 ItemCacheKey cache_key() const;
98 void paint();
99
100private:
101 SPItem const *_item;
102};
103
104} // namespace Inkscape::Extension::Internal::PdfBuilder
105
106#endif /* !EXTENSION_INTERNAL_PDF_CAPYPDF_H */
107
108/*
109 Local Variables:
110 mode:c++
111 c-file-style:"stroustrup"
112 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
113 indent-tabs-mode:nil
114 fill-column:99
115 End:
116*/
117// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Sequence of subpaths.
Definition pathvector.h:122
Sequence of contiguous curves, aka spline.
Definition path.h:353
Axis aligned, non-empty rectangle.
Definition rect.h:92
void paint_group(CapyPDF_TransparencyGroupId child_id, SPStyle const *style=nullptr, Geom::Affine const &tr=Geom::identity(), std::optional< CapyPDF_TransparencyGroupId > soft_mask={})
Paint a child group at the requested location.
void paint_item_to_raster(SPItem const *item, Geom::Affine const &tr, double resolution, bool antialias)
Draw an item as a bitmap and return.
void set_matrix(Geom::Affine const &affine)
Set the transformation matrix for this context Group.
std::optional< double > get_softmask(double opacity) const
void paint_raster(SPImage const *image)
Draw the raster data stored in URI into the PDF context.
void paint_item_clone(SPUse const *use, SPStyle const *context_style)
Paint the given clone object, finding or generating a transparency group from it.
void clip_text_layout(Text::Layout const &layout)
Use the text object as a clipping mask in the PDF.
void start_ocg(CapyPDF_OptionalContentGroupId ocgid)
void set_clip_rectangle(Geom::OptRect const &rect)
Apply the clipping rectangle with a NONZERO fill rule.
bool set_shape_pathvector(Geom::PathVector const &pathv)
DrawContext(Document &doc, capypdf::DrawContext ctx, bool soft_mask)
void set_clip_path(std::optional< Geom::PathVector > clip, SPStyle *style=nullptr)
Apply the clip path to the existing context.
void paint_item(SPItem const *item, Geom::Affine const &tr=Geom::identity(), SPStyle const *context_style=nullptr)
Paint the given object into the given context, making groups if needed.
void paint_shape(SPShape const *shape, SPStyle const *context_style)
Paint a single shape path.
void set_paint_style(StyleMap const &map, SPStyle const *style, SPStyle const *context_style)
Set the style for drawing shapes from the SVG style, this is all the styles that relate to how vector...
void paint_text_layout(Text::Layout const &layout, SPStyle const *context_style)
Paint the given layout into the PDF document Drawing content.
void transform(Geom::Affine const &affine)
Add a transform to the current context stream.
void paint_item_group(SPGroup const *group, SPStyle const *context_style)
Generates the layout for either wrapped or non-wrapped text and stores the result.
Definition Layout-TNG.h:144
Base class for visual SVG elements.
Definition sp-item.h:109
Base class for shapes, including <path> element.
Definition sp-shape.h:38
An SVG style object.
Definition style.h:45
Definition sp-use.h:25
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
std::unique_ptr< Magick::Image > image
SPItem * item
Affine identity()
Create an identity matrix.
Definition affine.h:210
std::tuple< std::string, std::string, std::string > ItemCacheKey
std::map< SPAttr, std::string > StyleMap
STL namespace.
static T clip(T const &v, T const &a, T const &b)