Skip to content

Implement antialiasing as an option for vector layers

Grum 999 requested to merge grum/krita:grum999/vector_layer_aliasing into master

Being able to disable anti-aliasing on Vector layer is something frequently asked on KA

This is an implementation of an option to activate/deactivate anti-aliasing on Vector Layer

  • The option is available from layer properties


  • The option is available from layers docker




From a technical point of view:

  • Layer properties UI use standard implementation through sectionModelProperties(), setSectionModelProperties(), KisLayerPropertiesIcons
    • I've used the icon curve-preset-s because it give a 'smooth' look I've tried to search on google what a 'anti-alias' icon could look but didn't find anything convincing me I'm open to ideas about this icon if the chosen one is not Ok 😄
  • The option is saved/loaded from Krita document (impact on impex/libkra)
  • Are concerned by activation/deactivation of anti-aliasing all shapes on vector layer, including text. This is made through:
    • KisShapeLayerCanvasBase::repaint() that set QPainter::Antialiasing only if vector option is set to True

    • KoSvgTextShape::paintPaths(), when given QPainter renderHint(QPainter::Antialiasing) is True

    • This works with "On canvas" text editing but may be its better @woltherav check I didn't broke or miss anything here with new text tool


  • Also, VectorLayer class from python API has been updated to let plugin developers being able to use this new option.

Notes concerning impact on class KisShapeLayer

  • I use if(m_d->canvas) m_d->canvas->resetCache(); to refresh canvas content when option is modified, not sure it's the best method
  • There's many KisShapeLayer constructors and I'm not sure I've updated them in the best way...

Test Plan

Test 1

  • Create a document, add one or more vector layer
  • Add shapes & text in vector layer, zoom on layer to have a better view of pixels (zoom 400% for example)
  • Open layer properties, check/uncheck "Antialiasing" option, see how layer is rendered according to option status; close properties
  • Change status from Layer docker, see how layer is rendered according to option status; close properties
  • Save document, close it
  • Open document, option status (activated/deactivated) should match what was defined when saved

Test 2

  • Open a document with vector layer, created from a previous version of Krita
  • Document must open and vector layers are antialiased

Test 3

  • Open a document created from Test 1 in a previous version of Krita
  • Document must open and all vector layers are antialiased (option is ignored, and will be lost is saved from a previous version)

Test 4

  • Open a document created from Test 1 in version of Krita with this MR implemented

  • Open scripter

  • Execute the following script

      from krita import (Document, Notifier)
      from PyQt5.Qt import *
      class TestVectorLayer():
          def __init__(self):
              doc = Krita.instance().activeDocument()
              if doc:
                  node = doc.rootNode()
                  for childNode in node.childNodes():                
                      if childNode.type() == "vectorlayer":
                          qDebug(f"{}: {childNode.isAntialiased()}")
                          childNode.setAntialiased(not childNode.isAntialiased())
      test = TestVectorLayer()
  • Check that status of option on vector layer has been switched

Test 5

Execute tests unit build with Krita

  • /krita-build/plugins/impex/libkra/tests/kis_kra_saver_test
  • /krita-build/plugins/impex/libkra/tests/kis_kra_loader_test

Note: the kis_kra_saver_test currently return 1 failure on master branch... the failure is still here in my MR


QWARN  : KisKraSaverTest::testRoundTrip() krita.core: BUG: The walker hasn't reached the root layer!
QWARN  : KisKraSaverTest::testRoundTrip() krita.core:      Start node: KisGroupLayer(0x557dbba0d950, name = "group1") Requested rect: QRect(-76,0 76x304)
QWARN  : KisKraSaverTest::testRoundTrip() krita.core:      An inconsistency in the walkers occurred!
QWARN  : KisKraSaverTest::testRoundTrip() krita.core:      Please report a bug describing how you got this message.
FAIL!  : KisKraSaverTest::testRoundTrip() 'result' returned FALSE. ()
  Loc: [/home/appimage/persistent/krita/plugins/impex/libkra/tests/kis_kra_saver_test.cpp(91)]

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list,

Edited by Deif Lou

Merge request reports