backingAlignedRect: doesn't align in magnified views

  • I have subclassed a NSView and placed it within a window.
    In this NSView I have to align my NSBezier rect to the pixel grid and stroke
    a perfect and aligned 1 pixel width rect.
    So, in the documentView's drawRect: method, I do

    [[NSGraphicsContext currentContext] setShouldAntialias:NO];
    [NSBezierPath setDefaultLineWidth:0.0];
    NSRect anyRect = NSMakeRect(50, 113.25, 110, 70.5);
    NSRect alignedRect = [self backingAlignedRect:anyRect
    options:NSAlignAllEdgesInward];
    [NSBezierPath strokeRect:alignedRect];

    It works when the clipView's is not magnified (scale 1:1), but if I magnify
    the view calling

    [self scaleUnitSquareToSize:NSMakeSize(scaleFactor, scaleFactor)];

    from within the magnifyWithEvent: method, I get, sometimes, a 2 width pixels
    line (wrong!). Is it a bug or do I miss something? For instance, when the
    view's mScaleFactor is 5.057041 (frame.size / bounds.size), I get a 2 pixels
    width line (wrong), and I get this log

    mScaleFactor 5.057041;
    anyRect 50.000000, 113.250000, 110.000000, 70.500000
    alignedRect 50.063373, 113.390257, 109.747964, 70.199148

    My screen is not retina. My screen's DPI is 133.
    Any solution will be welcome.

    Regards
    -- Leonardo
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today