Closed Bug 364300 Opened 18 years ago Closed 17 years ago

Monospace font isn't, with ATSUI, breaking "cols" attribute of <textarea>

Categories

(Core :: Graphics, defect, P1)

x86
macOS
defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha8

People

(Reporter: bzbarsky, Assigned: vlad)

Details

Attachments

(3 files, 2 obsolete files)

BUILD: Current trunk Mac build STEPS TO REPRODUCE: 1) Load data:text/html,<textarea style="font-family: monospace" cols="5" rows="3">01234 2) Hit enter 4 times 3) Scroll back up to the first line ACTUAL RESULTS: Observe that the numbers don't go up to the scrollbar. EXPECTED RESULTS: Numbers should go up to the scrollbar. MORE DATA: In nsTextControlFrame::CalcIntrinsicSize, the return values of GetAveCharWidth and GetMaxAdvance are different, even though this is a monospace font. I tried debugging, and in gfxAtsuiFont::gfxAtsuiFont for the monospace font we have: (gdb) p atsMetrics.maxAdvanceWidth $35 = 0.823242188 (gdb) p atsMetrics.avgAdvanceWidth $36 = 0 (gdb) p GetCharWidth(' ') $38 = 7.80126953 (gdb) p GetCharWidth('a') $39 = 7.80126953 (gdb) p GetCharWidth('-') $40 = 7.80126953 Here "size" is 13, so the the maxAdvanceWidth doesn't match the aveCharWidth we end up setting. The problem is that we need to be able to detect a fixed-width font in this case, and if the ave char width and max advance differ the font is clearly not fixed-width... in which case why are we using it for "monospace"? This is a pretty serious web-compat problem, for what it's worth -- the two sizing algorithms used in the two cases by <textarea> are pretty different. Sadly, I have no idea whether this is a cairo regression...
Flags: blocking1.9?
OS: Mac OS X 10.3 → Mac OS X 10.4
The monospace font doesn't mean that the all characters has same width. E.g., CJK characters need the width of 2 ASCII characters. And some characters are zero-width. Now, the Avg char width returns width of 'x' if ATSUI returns '0' or larger value than width of 'x' (e.g., Osaka-mono). (see bug 362665 comment 18.)
> E.g., CJK characters need the width of 2 ASCII characters. If that were all there were to it, we could try to deal. But in this case the max advance is some non-integral multiple of the average char width. I should note that the "2 ASCII characters" thing _does_ mean that there's no sane way to make "cols" work with such characters, btw. In the end, I couldn't care less what's returned for these various font metrics; from the point of view of layout I just want a 100% reliable way to detect monospace fonts being used so that we can set the width to cols * "the font's char width", defined in some way that makes the common use cases work. But only for monospace fonts, since for non-monopace ones IE does something different and we need to as well.
How about that we add the |isFixedPitch| flag for the metrics? Mac can get whether the font is fixed pitch font.
That would work for my use case, yes.
Or, should we set same value to maxAdvanceWidth and avgAdvanceWidth if the font is fixed pitch?
Flags: blocking1.9? → blocking1.9+
Assignee: nobody → vladimir
Target Milestone: --- → mozilla1.9alpha6
punting remaining a6 bugs to b1, all of these shipped in a5, so we're at least no worse off by doing so.
Target Milestone: mozilla1.9alpha6 → mozilla1.9beta1
I have a patch that checks whether a font is monospace, and if so, it forces avgAdvanceWidth = maxAdvanceWidth. However, that doesn't result in any different rendering for the given testcase -- there's still a bit of a space betwee the last digit and the start of the scrollbar. I think that's caused by a margin around the scrollbar itself, though; the scrollbar doesn't butt up to the top/right/bottom edges of the frame either, there's about 2-3 pixels of space... and I think those 2-3 pixels are on the left side as well. bz, are you seeing a worse spacing than this? cols=1,2,..5 all seem to be have correctly (they go up by the same amount, which looks to be the width of one char.
Attached patch the patch (obsolete) — Splinter Review
The patch, FWIW. (It might not apply cleanly, some of the context is from another patch, but it's fairly simple.)
Yeah, I'm seeing more space than that. I can post a screenshot if you like. I tried applying your patch, and it doesn't help. In GetOrMakeFont (in gfxAtsuiFonts.cpp) we name == "Courier" by the time we're calling gfxAtsuiFont::gfxAtsuiFont(), aFontID == 8197, and aFonts an empty array. aStyle seems as-expected. Then we call InitMetrics() with a fontRef of 8197. Then we ask the font cache whether the font with id 8197 is fixed-pitch, and it claims that it's not. That seems bogus for Courier... The FontEntry's mTraits is 0x100000c in this case. That looks like NSUnboldFontMask | NSNonStandardCharacterSetFontMask | NSUnitalicFontMask if I read http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSFontManager_Class/Reference/Reference.html right.
Here's what this looks like for me. A screenshot would be helpful, just so I know what to look for. Can you also tell me what your font settings are? I can't manage to reproduce this and I just tried a bunch of different fonts set as the monospace font, the default was Courier 13 (which is what this screenshot is using).
That's exactly what my screenshot looks like. That's not right. And it's a lot more space than on the other sides of the scrollbar. More importantly, just stepping though the code in nsTextControlFrame::CalcIntrinsicSize gives me a GetAveCharWidth of 468 and GetMaxAdvance of 643, so we go down the variable-width font sizing codepath instead of the fixed-width font sizing codepath. That's the bug. The text rendering itself is correct, of course. It's just the sizing of the input control that's off. My font prefs are whatever we default to, which is Courier 13, looks like. As I said, your screenshot looks just like mine. ;)
Attached image win32 screenshot
Oddness.. on win32, data:text/html,<textarea style="font-family: Courier New; font-size: 13pt;" cols="5" rows="3">01234</textarea> other fonts look fine (though "fine" means that they tend to end up with a horizontal scrollbar once they have 5 characters in there when the vertical scrollbar shows up) But, I'll debug it via looking at the metrics themselves.
Uh.. Interesting. On linux here, "Courier New" gives me a variable-width font (which might just be because it's not installed). "Courier" gives me a fixed-width font and works as it should. I wonder what's up with the Windows code. What do you see in nsTextControlFrame::CalcIntrinsicSize ?
Attached patch fix (obsolete) — Splinter Review
This fixes it, I think -- the problem earlier was that IsFixedPitch() was always returning false, because that trait was never appearing in the traits list... asking the font directly whether it's fixed pitch or not returns the correct value. I dunno. Now, I'd still like to know why these fonts report a different average character width from max advance -- both those metrics are coming straight from the type system.
Attachment #271520 - Attachment is obsolete: true
Attachment #272225 - Flags: review?(roc)
Interesting. http://lists.apple.com/archives/cocoa-dev/2001/Dec/msg00836.html lists exactly the value I was seeing for mTraits. Maybe traitsOfFont is just busted in some cases?
That patch still doesn't quite work over here. The reason is that GetAveCharWidth() does ROUND_TO_TWIPS and GetMaxAdvance() does CEIL_TO_TWIPS. So the former ends up 468 twips and the latter ends up 469 twips, given the starting value of 7.80126953125. 7.80126953125 * 60 == 468.076...., which is where we get those numbers.
Attached patch fix, 2.0Splinter Review
Let's just get rid of using traitsOfFont entirely, based on bz's info.
Attachment #272225 - Attachment is obsolete: true
Attachment #272229 - Flags: review?(roc)
Attachment #272225 - Flags: review?(roc)
If I make both functions ROUND_TO_TWIPS, I get the rendering I would expect on the testcase. Oh, and this is the only caller of GetMaxAdvance() in the tree, as far as I can tell...
So... I see the same issue on Linux. I guess I should file a separate bug on this, eh?
I filed bug 388179 on the Linux issue. Does Windows have a similar problem?
This was checked in; resolving.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
It looks like comment 16 never got addressed. See bug 428458, which I suspect is caused by that.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: