[QGIS-trac] Re: [Quantum GIS] #1262: Point and Multipoint symbols are not drawn centered at location

Quantum GIS qgis at qgis.org
Thu Nov 13 21:10:32 EST 2008


#1262: Point and Multipoint symbols are not drawn centered at location
----------------------------------------------------+-----------------------
        Reporter:  smizuno                          |         Owner:  homann       
            Type:  bug                              |        Status:  reopened     
        Priority:  minor: annoyance or enhancement  |     Milestone:  Version 1.0.0
       Component:  Marker Symbols                   |       Version:  HEAD         
      Resolution:                                   |      Keywords:               
Platform_version:                                   |      Platform:  All          
        Must_fix:  No                               |   Status_info:  0            
----------------------------------------------------+-----------------------
Changes (by smizuno):

  * status:  closed => reopened
  * resolution:  wontfix =>

Comment:

 I reopen this ticket because I have a patch for QgsMarkerCatalogue that
 draws the hard-coded point symbols more accurately than the existing one
 does.

 I took this as a challenge as I believed that it was possible to draw the
 point symbols accurately, at least within one pixel.

 The problems I found:[[BR]]
 1. some calls (for circle and square) to QPainter::drawXXX() functions had
 two points passed in - these should have been upper left location and
 size; this is the main reason that the fudge factors had to be
 employed.[[BR]]
 2. calls to QPainter::drawXXX() functions had float calculations, but the
 functions took integers - this causes whole pixel differences (left and
 up) due to truncation plus any other differences that occur elsewhere.
 This is why the symbols were clipped on the left and top.[[BR]]
 3. the QImage may have an even number of pixels on a side, which makes it
 difficult to center.[[BR]]

 What my patch does in imageMarker() and hardMarker():[[BR]]
 1. makes the QImage have an odd number of pixels for width and height, so
 the center of the image can be placed properly. Also, the image width and
 height are odd for SVG rendering.[[BR]]
 2. allows for the pen width, including Qt cosmetic pen (width=0, actually
 one pixel) when sizing QImage[[BR]]
 3. uses floating point calculations, objects, and calls to the draw
 functions - QPointF, QPolygonF, QRectF, and such, leaving the conversion
 to integer pixel locations to the Qt draw functions.[[BR]]
 4. the QImage size is passed to hardMarker() for centering the figure when
 drawing it. The hardMarker() function has an additional parameter. It is a
 private function, so the API is not affected.[[BR]]
 5. provides proper rounding of float values to integer when centering the
 figure[[BR]]
 6. pictureMarker() isn't currently used, I believe, so it is modified only
 so function calls are correct. Perhaps this function should be
 removed?[[BR]]
 7. includes M_PI and DEG2RAD macros for some figure calculations[[BR]]
 8. removes the iostream include as this interferes with the data stream
 operators used to send data into QPolygonF

 Once I had it working I created three additional symbols (equilateral
 triangle, pentagon, regular star) using mathematical models, which were
 drawn centered as expected.

 Now, symbols like the crosses are drawn on the map canvas with the point
 at which the lines cross at the location in question (within one pixel).

 As submitted, filled figures are drawn at the size specified and then the
 outline is added - half inside, half outside the figure - as Qt's notion
 of outline. I provided some alternate code (the #if 0 block in hardMarker
 ) to keep the overall symbol size at the specified size.

 The patch is against r9611.

 I am using Windows XP and Qt 4.4.0; also have tested on Linux / Qt 4.3.3

-- 
Ticket URL: <https://trac.osgeo.org/qgis/ticket/1262#comment:7>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats


More information about the QGIS-trac mailing list