惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
美团技术团队
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
V
V2EX
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
量子位
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Jina AI
Jina AI
月光博客
月光博客
L
LangChain Blog

Martin Owens activity

Martin Owens deleted project branch average-color-divide at Inkscape / inkscape Fix divide-by-zero crash when using calligraphy tool (d34276f8) · Commits · Inkscape / inkscape · GitLab Fix divide-by-zero crash when using calligraphy tool (!7923) · Merge requests · Inkscape / inkscape · GitLab Add selection file to bypass Windows command length limits (correction) (865df7a5) · Commits · Inkscape / inkscape · GitLab Draft: Fix AppImage crashing during save on older distros (!7922) · Merge requests · Inkscape / inkscape · GitLab e71fa7f8e0858aab87b7fc0814a30a8c88da9b43 to fe225a6b9e1042c7221d95173be22a02b3725337 · Martin Owens / inkscape · GitLab 403 Forbidden on Inkscape web server (#693) · Issues · Inkscape / inkscape-web · GitLab 403 Forbidden on Inkscape web server (#13509) · Issues · Inkscape / Inbox · GitLab Add selection file to bypass Windows command length limits (correction) (!7917) · 合并请求 · Inkscape / inkscape · GitLab Non-vertical axonometric axis implementation (!7912) · Merge requests · Inkscape / inkscape · GitLab Update split mode on tab switch (!7915) · Merge requests · Inkscape / inkscape · GitLab inset/offset as app functions so they can be used from CLI (!7914) · Merge requests · Inkscape / inkscape · GitLab Performace regresion in last month (#5879) · Issues · Inkscape / inkscape · GitLab [Regression] Right-aligned text has a new gap in 1.4.4 (#6130) · Issues · Inkscape / inkscape · GitLab [Regression] Right-aligned text has a new gap in 1.4.4 (#13498) · Issues · Inkscape / Inbox · GitLab c503804e014994d611de1b225bee8158c06448a8 to a4588d8ead1e7049b90c5a126962746ed286ab17 · Inkscape / inkscape-web · GitLab Validate the extensions of signature file uploads (a4588d8e) · 提交 · Inkscape / inkscape-web · GitLab Allow color conversions using static arrays instead of just vectors (e71fa7f8) · 提交 · Martin Owens / inkscape · GitLab Speed up ungroup on thousands of items (!7908) · Merge requests · Inkscape / inkscape · GitLab Incorrect handling of FontMatrix and transformation matrices with internal PDF import (#4845) · Issues · Inkscape / inkscape · GitLab Handling edge case of negative fonts in PDF (59040229) · 提交 · Inkscape / inkscape · GitLab Handling edge case of negative fonts in PDF (!7911) · 合并请求 · Inkscape / inkscape · GitLab Allow color conversions using static arrays instead of just vectors (33e65d1b) · Commits · Martin Owens / inkscape · GitLab Allow color conversions using static arrays instead of just vectors (9be5f867) · Commits · Martin Owens / inkscape · GitLab a9672ea1dff483b5b3aa8c6b5d88cd223001bef5 to 512a5e57602ac52e1d35782a7dcebae04262b2b8 · Martin Owens / inkscape · GitLab Add selection file to bypass Windows command length limits (!7905) · 合并请求 · Inkscape / inkscape · GitLab Revert Pango label changes (1.4.x) (!7907) · 合并请求 · Inkscape / inkscape · GitLab Crash on selecting a `<text>` object without a `<tspan>` inside (#5462) · Issues · Inkscape / inkscape · GitLab Fix breakage with Ubuntu 26.04 CI (!7904) · 合并请求 · Inkscape / inkscape · GitLab c673fdd5148253276826d4eda3951daaefb82607 to 356b31383ba324396a225686613236484305533d · Martin Owens / inkscape · GitLab
Refactor paint server data so the renderer works from dat...
Martin Owens · 2026-04-19 · via Martin Owens activity
Commit c821845d authored by Martin Owens's avatar Martin Owens 🕘
Browse files
This allows the paint server code to be unit tested in later versions. There are some limitations
to this refactoring including use of virtual functions instead of casting so we can use templates
in renderers.

ll SPObjects must implement their virtual functions, so the base classes all return empty objects
where possible and this pushed the design in a certain direction for some calls.

 * Move sp-gradient spread, units and vector to sp-paint-server-data.h
 * Move mesh gradient patches data from display/drawing-paintserver to sp-paint-server-data
 * Allow SPPaintServer to be used as a template class in a renderer by providing data from sp-paint-server-data in a consistant way from the base class using virtual functions.
 * Add getPaintType and enum class to decide what type of paint server we have instead of cast
 * Add SPGradient virtual for gathering geometric gradient data for Lienar and Radial gradients
 * Add SPMeshGradient virtual for gathering mesh patches data for the Mesh gradient
 * Pack gradient geometric data into SPGradientVector and return in getGradientVector
 * Harmonize const and API between Mesh Gradients and Linear/Radial Gradients
 * Move add create_drawing_paintserver calls to display/drawing-paintserver in a single call
 * Remove `mg` MeshGradient pointer from MeshArray and remove back-linking. This indicates bad
   API design for some of these calls as the functions used mg and had little to do with the MeshArray
   but for now we just push the MeshGradient object back in as an argument.
 * Change drawing-paintserver constructors to take paint-server-data objects instead of individual arguments.
+20 −0
Original line number Diff line number Diff line
@@ -5,9 +5,29 @@

#include "cairo-utils.h"
#include "colors/color.h"
#include "object/sp-paint-server.h"

namespace Inkscape {

std::unique_ptr<Inkscape::DrawingPaintServer> create_drawing_paintserver(SPPaintServer *ps)
{
    switch (ps->getPaintType()) {
        case PaintServerType::SOLID_COLOR:
            return std::make_unique<Inkscape::DrawingSolidColor>(ps->getSolidColor());
            break;
        case PaintServerType::LINEAR_GRADIENT:
            return std::make_unique<Inkscape::DrawingLinearGradient>(ps->getSpread(), ps->getUnits(), ps->getGradientTransform(), ps->getGradientVector());
            break;
        case PaintServerType::RADIAL_GRADIENT:
            return std::make_unique<Inkscape::DrawingRadialGradient>(ps->getSpread(), ps->getUnits(), ps->getGradientTransform(), ps->getGradientVector());
            break;
        case PaintServerType::MESH_GRADIENT:
            return std::make_unique<Inkscape::DrawingMeshGradient>(ps->getSpread(), ps->getUnits(), ps->getGradientTransform(), ps->getGradientMesh());
            break;
    }
    return {};
}

DrawingPaintServer::~DrawingPaintServer() = default;

DrawingSolidColor::DrawingSolidColor(Colors::Color color)
+24 −32
Original line number Diff line number Diff line
@@ -16,11 +16,10 @@
#include <cairo.h>
#include <2geom/rect.h>
#include <2geom/affine.h>
#include "object/sp-gradient-spread.h"
#include "object/sp-gradient-units.h"
#include "object/sp-gradient-vector.h"
#include "object/sp-paint-server-data.h"

class SPGradient;
class SPPaintServer;

namespace Inkscape {
namespace Colors {
@@ -96,13 +95,13 @@ class DrawingLinearGradient final
{
public:
    DrawingLinearGradient(SPGradientSpread spread, SPGradientUnits units, Geom::Affine const &transform,
                          float x1, float y1, float x2, float y2, std::vector<SPGradientStop> stops)
                          SPGradientVector const *vector)
        : DrawingGradient(spread, units, transform)
        , x1(x1)
        , y1(y1)
        , x2(x2)
        , y2(y2)
        , stops(std::move(stops)) {}
        , x1(vector->geom[0])
        , y1(vector->geom[1])
        , x2(vector->geom[2])
        , y2(vector->geom[3])
        , stops(vector->stops) {}

    cairo_pattern_t *create_pattern(cairo_t*, Geom::OptRect const &bbox, double opacity) const override;

@@ -119,22 +118,22 @@ class DrawingRadialGradient final
{
public:
    DrawingRadialGradient(SPGradientSpread spread, SPGradientUnits units, Geom::Affine const &transform,
                          float fx, float fy, float cx, float cy, float r, float fr, std::vector<SPGradientStop> stops)
                          SPGradientVector const *vector)
        : DrawingGradient(spread, units, transform)
        , fx(fx)
        , fy(fy)
        , cx(cx)
        , cy(cy)
        , r(r)
        , fr(fr)
        , stops(std::move(stops)) {}
        , cx(vector->geom[0])
        , cy(vector->geom[1])
        , r(vector->geom[2])
        , fx(vector->geom[3])
        , fy(vector->geom[4])
        , fr(vector->geom[5])
        , stops(vector->stops) {}

    cairo_pattern_t *create_pattern(cairo_t *ct, Geom::OptRect const &bbox, double opacity) const override;

    bool uses_cairo_ctx() const override { return true; }

private:
    float fx, fy, cx, cy, r, fr;
    float cx, cy, r, fx, fy, fr;
    std::vector<SPGradientStop> stops;
};

@@ -145,30 +144,23 @@ class DrawingMeshGradient final
    : public DrawingGradient
{
public:
    struct PatchData
    {
        Geom::Point points[4][4];
        char pathtype[4];
        bool tensorIsSet[4];
        Geom::Point tensorpoints[4];
        std::optional<Colors::Color> color[4];
    };

    DrawingMeshGradient(SPGradientSpread spread, SPGradientUnits units, Geom::Affine const &transform,
                        int rows, int cols, std::vector<std::vector<PatchData>> patchdata)
                        SPGradientMesh const *mesh)
        : DrawingGradient(spread, units, transform)
        , rows(rows)
        , cols(cols)
        , patchdata(std::move(patchdata)) {}
        , rows(mesh->rows)
        , cols(mesh->cols)
        , patchdata(mesh->patches) {}

    cairo_pattern_t *create_pattern(cairo_t*, Geom::OptRect const &bbox, double opacity) const override;

private:
    int rows;
    int cols;
    std::vector<std::vector<PatchData>> patchdata;
    std::vector<std::vector<SPGradientPatch>> patchdata;
};

std::unique_ptr<Inkscape::DrawingPaintServer> create_drawing_paintserver(SPPaintServer *ps);

} // namespace Inkscape

#endif // INKSCAPE_DISPLAY_DRAWING_PAINT_SERVER_H
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ void NRStyleData::Paint::set(SPPaintServer *ps)
    clear();
    if (ps) {
        type = PaintType::SERVER;
        server = ps->create_drawing_paintserver();
        server = create_drawing_paintserver(ps);
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ namespace XML {}
 *     - SPMask [\ref sp-mask.cpp, \ref sp-mask.h]
 *     - SPNamedView [\ref sp-namedview.cpp, \ref sp-namedview.h]
 *   - SPPaintServer [\ref sp-paint-server.cpp, \ref sp-paint-server.h]
 *     - SPGradient [\ref sp-gradient.cpp, \ref sp-gradient.h, \ref gradient-chemistry.cpp, \ref sp-gradient-reference.h, \ref sp-gradient-spread.h, \ref sp-gradient-units.h, \ref sp-gradient-vector.h]
 *     - SPGradient [\ref sp-gradient.cpp, \ref sp-gradient.h, \ref gradient-chemistry.cpp, \ref sp-gradient-reference.h, \ref sp-paint-server-data.h]
 *       - SPLinearGradient
 *       - SPRadialGradient
 *     - SPPattern [\ref sp-pattern.cpp, \ref sp-pattern.h]
+1 −1
Original line number Diff line number Diff line
@@ -1274,7 +1274,7 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain
            ink_cairo_pattern_add_color_stop(pattern, rg->vector.stops[i].offset, *rg->vector.stops[i].color, alpha);
        }
    } else if (auto mg = cast<SPMeshGradient>(paintserver_mutable)) {
        pattern = mg->create_drawing_paintserver()->create_pattern(_cr, pbox, 1.0);
        pattern = Inkscape::create_drawing_paintserver(mg)->create_pattern(_cr, pbox, 1.0);
    } else if (is<SPPattern>(paintserver)) {
        pattern = _createPatternPainter(paintserver, pbox);
    } else if (is<SPHatch>(paintserver) ) {