30 return CAPY_BM_MULTIPLY;
32 return CAPY_BM_SCREEN;
34 return CAPY_BM_DARKEN;
36 return CAPY_BM_LIGHTEN;
38 return CAPY_BM_OVERLAY;
40 return CAPY_BM_COLORDODGE;
42 return CAPY_BM_COLORBURN;
44 return CAPY_BM_HARDLIGHT;
46 return CAPY_BM_SOFTLIGHT;
48 return CAPY_BM_DIFFERENCE;
50 return CAPY_BM_EXCLUSION;
54 return CAPY_BM_SATURATION;
58 return CAPY_BM_LUMINOSITY;
62 return CAPY_BM_NORMAL;
69 return CAPY_LC_PROJECTION;
98 if (style->
fill.set && style->
fill.href) {
116 std::vector<PaintLayer> output;
119 auto context_paint_is_none = [context_style](
SPIPaint const &paint) {
123 bool no_fill = style->
fill.isNone() || style->
fill_opacity.value < 1e-9 || context_paint_is_none(style->
fill);
124 bool no_stroke = style->
stroke.isNone() ||
127 context_paint_is_none(style->
stroke);
129 if (no_fill && no_stroke) {
135 for (
auto i = 0; i < 3; i++) {
136 auto layer = layers[i];
164 (style->
fill.set && style->
fill.href && style->
fill.href->getObject()) ||
178 return std::to_string(*opacity);
183 return paint.
href->getObject()->getId();
202 if (
auto child_item = cast<SPItem>(&obj)) {
218std::optional<CapyPDF_GraphicsStateId>
225 auto gstate = capypdf::GraphicsState();
226 bool gs_used =
false;
229 auto smask = capypdf::SoftMask(CAPY_SOFT_MASK_LUMINOSITY, *soft_mask);
230 gstate.set_SMask(
_gen.add_soft_mask(smask));
242 return _gen.add_graphics_state(gstate);
259 auto gstate = capypdf::GraphicsState();
260 bool gs_used =
false;
263 auto smask = capypdf::SoftMask(CAPY_SOFT_MASK_LUMINOSITY, *soft_mask);
264 gstate.set_SMask(
_gen.add_soft_mask(smask));
277 return _gen.add_graphics_state(gstate);
295 }
catch (std::exception
const &
err) {
296 std::cerr <<
"Can't load font: '" << filename.c_str() <<
"'\n";
307 std::optional<double> opacity)
327 if (
auto pattern_id =
get_pattern(paint.
href ? paint.
href->getObject() :
nullptr, opacity)) {
328 out.set_pattern(*pattern_id);
330 g_warning(
"Couldn't generate pattern for fill '%s'", paint.
get_value().c_str());
334 g_warning(
"Context style requested but no context style available.");
335 out.set_rgb(0, 0, 0);
337 g_warning(
"Fill style not supported: '%s'", paint.
get_value().c_str());
338 out.set_rgb(0, 0, 0);
350 }
else if (
auto cmyk = std::dynamic_pointer_cast<Colors::Space::DeviceCMYK>(space)) {
351 out.set_cmyk(color[0], color[1], color[2], color[3]);
352 }
else if (
auto cms = std::dynamic_pointer_cast<Colors::Space::CMS>(space)) {
355 out.set_icc(*icc_id, vals.data(), vals.size());
357 g_warning(
"Couldn't set icc color, icc profile didn't load.");
360 out.set_rgb(
rgb->get(0),
rgb->get(1),
rgb->get(2));
362 g_warning(
"Problem outputting color '%s' to PDF.", color.
toString().c_str());
363 out.set_rgb(0, 0, 0);
370 auto key = profile->getName();
375 if (
auto cms_profile = profile->getProfile()) {
376 auto channels = profile->getComponentCount();
377 auto vec = cms_profile->dumpData();
378 CapyPDF_IccColorSpaceId
id =
379 _gen.add_icc_profile(
reinterpret_cast<char const *
>(vec.data()), vec.size(), channels);
389 return CAPY_DEVICE_CS_RGB;
394 if (std::dynamic_pointer_cast<Colors::Space::DeviceCMYK>(space)) {
395 return CAPY_DEVICE_CS_CMYK;
396 }
else if (std::dynamic_pointer_cast<Colors::Space::RGB>(space)) {
397 return CAPY_DEVICE_CS_RGB;
398 }
else if (
auto cms = std::dynamic_pointer_cast<Colors::Space::CMS>(space)) {
400 g_warning(
"ICC profile color space expressed as device color space!");
401 switch (cms->getType()) {
403 return CAPY_DEVICE_CS_RGB;
405 return CAPY_DEVICE_CS_CMYK;
411 return CAPY_DEVICE_CS_RGB;
436 _ctx.set_nonstroke(*color);
441 _ctx.set_stroke(*color);
460 if (!values.empty()) {
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
std::optional< Color > converted(Color const &other) const
Return a copy of this color converted to the same format as the other color.
double getOpacity() const
Get the opacity in this color, if it's stored.
std::shared_ptr< Space::AnySpace > const & getSpace() const
const std::vector< double > & getValues() const
CapyPDF_Device_Colorspace get_default_colorspace() const
std::optional< CapyPDF_GraphicsStateId > get_group_graphics_state(SPStyle const *style, std::optional< CapyPDF_TransparencyGroupId > sm)
Set the style for any graphic from the SVG style.
std::map< std::string, CapyPDF_FontId > _font_cache
std::optional< CapyPDF_FontId > get_font(std::string const &filename)
Load a font and cache the results.
std::optional< capypdf::Color > get_paint(SPIPaint const &paint, SPStyle const *context_style, std::optional< double > opacity)
Generate a solid color, gradient or pattern based on the SPIPaint.
std::optional< CapyPDF_GraphicsStateId > get_shape_graphics_state(SPStyle const *style)
Like get_graphics_style but for drawing shapes (paths)
std::optional< CapyPDF_IccColorSpaceId > get_icc_profile(std::shared_ptr< Colors::Space::CMS > const &profile)
std::map< std::string, CapyPDF_IccColorSpaceId > _icc_cache
std::optional< CapyPDF_TransparencyGroupId > style_to_transparency_mask(SPStyle const *style, SPStyle const *context_style)
Render gradient transparencies into a transparency mask.
capypdf::Color get_color(Colors::Color const &color, std::optional< double > opacity)
CapyPDF_Device_Colorspace get_colorspace(std::shared_ptr< Colors::Space::AnySpace > const &space) const
std::optional< CapyPDF_PatternId > get_pattern(SPPaintServer const *paint, std::optional< double > opacity)
Construct a PDF pattern object from the given paintserver.
std::optional< double > get_softmask(double opacity) const
capypdf::DrawContext _ctx
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...
Paint type internal to SPStyle.
bool isPaintserver() const
const Glib::ustring get_value() const override
std::shared_ptr< SPPaintServerReference > href
SPPaintOrigin paintOrigin
Colors::Color const & getColor() const
Base class for visual SVG elements.
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
T< SPAttr::FILL, SPIPaint > fill
fill
T< SPAttr::STROKE_DASHARRAY, SPIDashArray > stroke_dasharray
stroke-dasharray
T< SPAttr::STROKE, SPIPaint > stroke
stroke
T< SPAttr::PAINT_ORDER, SPIPaintOrder > paint_order
T< SPAttr::STROKE_WIDTH, SPILength > stroke_width
stroke-width
T< SPAttr::FILL_OPACITY, SPIScale24 > fill_opacity
fill-opacity
T< SPAttr::STROKE_LINEJOIN, SPIEnum< SPStrokeJoinType > > stroke_linejoin
stroke-linejoin
T< SPAttr::STROKE_OPACITY, SPIScale24 > stroke_opacity
stroke-opacity
T< SPAttr::STROKE_MITERLIMIT, SPIFloat > stroke_miterlimit
stroke-miterlimit
T< SPAttr::MIX_BLEND_MODE, SPIEnum< SPBlendMode > > mix_blend_mode
T< SPAttr::OPACITY, SPIScale24 > opacity
opacity
T< SPAttr::STROKE_LINECAP, SPIEnum< SPStrokeCapType > > stroke_linecap
stroke-linecap
T< SPAttr::STROKE_DASHOFFSET, SPILength > stroke_dashoffset
stroke-dashoffset
T< SPAttr::STROKE_EXTENSIONS, SPIStrokeExtensions > stroke_extensions
-inkscape-stroke
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
CapyPDF_Line_Join get_linejoin(SPStrokeJoinType mode)
bool style_has_gradient_transparency(SPStyle const *style)
Returns true if the gradient has transparency.
bool gradient_has_transparency(SPPaintServer const *paint)
Returns true if the gradient has transparency.
CapyPDF_Blend_Mode get_blendmode(SPBlendMode mode)
Get the blend mode for capyPDF output.
std::string paint_to_cache_key(SPIPaint const &paint, std::optional< double > opacity)
Turn a paint into a string for use in caching keys.
CapyPDF_Line_Cap get_linecap(SPStrokeCapType mode)
void get_context_use_recursive(SPItem const *item, bool &fill, bool &stroke)
Find out if any of the item, or its decendents use context-fill and context-stroke.
std::vector< PaintLayer > get_paint_layers(SPStyle const *style, SPStyle const *context_style)
Get a PDF specific layer painting pattern for fill, stroke and markers.
bool style_needs_group(SPStyle const *style)
Return true if this shape's style requires a PDF transparency group.
static void err(const char *fmt,...)
std::map< SPAttr, std::string > StyleMap
static cairo_user_data_key_t key
Authors: see git history.
@ SP_CSS_BLEND_LUMINOSITY
@ SP_CSS_BLEND_DIFFERENCE
@ SP_CSS_BLEND_COLORDODGE
@ SP_CSS_BLEND_SATURATION
@ SP_STROKE_LINEJOIN_MITER
@ SP_STROKE_LINEJOIN_BEVEL
@ SP_STROKE_LINEJOIN_ROUND
@ SP_STROKE_LINECAP_SQUARE
@ SP_STROKE_LINECAP_ROUND
@ SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE
@ SP_CSS_PAINT_ORIGIN_CONTEXT_FILL
@ SP_CSS_PAINT_ORDER_STROKE
@ SP_CSS_PAINT_ORDER_MARKER
@ SP_CSS_PAINT_ORDER_FILL
SPStyle - a style object for SPItem objects.