How can you make a NSTextField render text like NSTextView when it does not draw its own background?

macOS 10.14.6, Non Retina Apple Cinema Displays (both the 27" and the terrific 30"). 

Problem:

I'm observing 2 different text rendering results depending on whether the text is drawn in a NSTextField or a NSTextView.
  • In both cases, the font, text, foreground and "background" colors are the same.

  • The background color is black.

  • The foreground color can be white, red, gray or green.

  • The NSTextField is located in a NSTableCellView, does not draw its background. The background color is defined in the NSTableView.


In the NSTextView, the text looks good.

In the NSTextField, the text does not look good (either the glyphs are thinner or the color is not as accurate).


I'm not saying this is totally surprising. But I would like the NSTextField(Cell) rendering to be as good as the NSTextView one.


Solutions already tested:
  1. looking for a solution on SO. One result where someone wanted the opposite : NSTextView to render the same way as NSTextField. So, nope.

  2. subclassing NSTextFieldCell:

This case is interesting. If you subclass NSTextFieldCell and override:

Code Block
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

so that it just calls the super method, then the text rendering is different than the NSTextFieldCell one.

If you just subclass NSTextFieldCell and do not override any method, then the rendering is the same as the NSTextFieldCell one.

So there must be some code in AppKit to render text differently for a NSTextFieldCell if some of the drawing methods are not the original ones.

When overriding - drawInteriorWithFrame:inView: and aplying some changes to the context with:
  • the text drawing mode

  • antialiasing

  • font smoothing

  • font subpixel quantization

I have not been able to reproduce the rendering of NSTextView.

Yet, imagining a function to set the font smoothing background color existed, this would provide a rendering closer to the NSTextView one. But of course, this is just pure imagination.

3. setting the background color of the NSTextField(Cell) to background color of the tableview and set drawsBackground to YES:

This does not help if you do not subclass NSTextFieldCell and override the drawing methods. If you do, then the text rendering is closer to the one in NSTextView but the issue is that when you select the row, the background of the NSTextField(Cell) is drawn over the highlrow selection rect. Playing with a custom NSTableRowView to fix this led to no results so far.

Question:

How can you make a NSTextField render text like NSTextView when the NSTextField does not draw its own background?