Skip to content

AttributedString boundingRectWithSize vs drawInRect #350

@rmottola

Description

@rmottola

in HelpViewer NoteCells are drawn in attachments.

First, the cell is sized and using pseudo-infinity height, the best width is determined:

	size.width -= leadingMargin*2;
	size.height = 9999.0;
	if (size.width <= 0)
	  size.width = [textView bounds].size.width;
        noteSize = [_note boundingRectWithSize:size options:0].size;

then, later, it is drawn:

      noteRect.origin = noteOrigin;
      noteRect.size = noteSize;
      [_note drawInRect: noteRect];

amazingly, this fails for certain strings. The issue was found with single-line strings where the string gets just truncated.

At a first glance, boundingRectWithSize returns a decent-wide enough size, it looks that drawInRect is not following it.
Also, the error doesn't seem constant.

Attributed String:

<b>{NSFont = "<NSFont: 0x562750b36720> DejaVuSansMono 12.000 0.000 0.000 12.000 0.000 0.000 P 0"; }votre texte en gras{NSFont = "<NSFont: 0x562750a8a120> TrebuchetMS-Bold 12.000 0.000 0.000 12.000 0.000 0.000 P 0"; }</b>{NSFont = "<NSFont: 0x562750b36720> DejaVuSansMono 12.000 0.000 0.000 12.000 0.000 0.000 P 0"; }

Size:

resizeWithTextView size: {width = 336; height = 9999} noteSize: {width = 158; height = 15}

Debug shows us reasonable text with a width of 158, yet it clips:

Image

empirically, I determined the error to be more than 10, less or equal to 15. Adding 15 to the width, makes the string (and others) draw. I suppose this is due to even off-by-one character causing a newline which is then clipped, since the height remained one-line.

Metadata

Metadata

Labels

bugA bug, but not a show stopper

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions