I need to render a vector-only SVG without antialiasing in Qt; specifically, I don't want the resulting image to contain any color that was not exactly as specified in the source file.
When loading an SVG in a QImage, Qt by default uses antialiasing; even using explicitly QSvgRenderer::render, the QPainter::Antialiasing render hint is ignored.
This turns out to be obvious, as QSVGTinyDocument::draw, which seems to be the one who actually starts the drawing, is forcing it set:
//sets default style on the painter
//### not the most optimal way
mapSourceToTarget(p, bounds);
QPen pen(Qt::NoBrush, 1, Qt::SolidLine, Qt::FlatCap, Qt::SvgMiterJoin);
pen.setMiterLimit(4);
p->setPen(pen);
p->setBrush(Qt::black);
p->setRenderHint(QPainter::Antialiasing);
p->setRenderHint(QPainter::SmoothPixmapTransform);
To circumvent this I tried to create a custom QPaintEngine wrapping the default one (and then subclass even QImage to return the wrapper QPaintEngine in the paintEngine() virtual method), but I couldn't find any clean way to intercept and alter the render hint on the way to the actual QPaintEngine.
The QPaintEngine::update() method, which seems to be the way through which a QPaintEngine receives the flags, receives a reference to a QPaintEngineState, which is a horrible kludge that provides only getters, which in turn
aren't virtual, so you cannot provide your implementation;
internally just assumes it's actually operating an instance of an internal subclass (QPainterState) by brutally casting the this pointer and accessing its fields.
Besides, even just providing a just-forwarding QPaintEngine resulted in segfaults inside the bowels of QPainter code, so I quickly desisted.
Long story short:
is there a way to forcibly disable/intercept and ignore/... the QPainter::Antialiasing render hint on a QPainter? (the QT_NO_ANTIALIASING environment variable doesn't count, as it is enabled only in builds without QT_NO_DEBUG);
more in general, how can I render an SVG to a QImage without antialising?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)