Closed kbuffington closed 3 years ago
@marc2k3 CalcTextWidth
will be affected in JSP as well, although over there at least GdiDrawText
does not claim to return any values :)
This new code doesn't like large strings/being called repeatedly as is done by the EstimateLineWrap function. It freezes fb2k indefinitely until you kill it with task manager. Try the last.fm bio sample.
Yeah, I'm seeing the same thing. For some reason I've never been able to attach to FSM's dll's to debug exactly what's going wrong. I can understand it being slow, but doesn't make sense why it would lock up FB.
Simple solution would be to have EstimateLineWraps's recursive functions continue to always call GetTextExtentPoint32 I suppose.
Should be safe now as it only calls DrawText from CalcTextWidth, and in all other cases uses the less accurate version which should be perfectly fine.
This is buggy if the text contains ampersands. You need to combine DT_NOPREFIX
with DT_CALCRECT
when using DrawText
.
D'oh. Should have caught that. Also added a check to skip this block if text.length is 1 or less. Kerning pairs don't matter if you can't have a kerning pair.
@kbuffington thanks for your contribution! There are a few things that need to be changed before it can be merged though:
@kbuffington can you fix (and test) the PR, plz? So that I could include it in the release (which I'm planning to ship soon).
Yeah, I'll try to make some time for this. I'm not completely sure what you meant by: "DT_SINGLELINE should be added to DrawText call." but I haven't looked at the code in a month so maybe it'll make more sense when I do.
DT_SINGLELINE single line causes method to ignore new lines (i.e. \n
), this way it would work the same as GetTextExtentPoint32
After looking at the code I understand what you were referencing and will add that.
Believe I've addressed everything, retested with new optional parameters and it all seems good.
Awesome, thanks!
I discovered that if a font has kerning pairs and the text you wish to get the width of contains one (or more) of those pairs the value of
CalcTextWidth
will be off for each pair in the text. I couple You's or To's and things get really bad really quickly (the cursor and highlighted text should be directly adjacent to the previous Y):See discussion here where the suggestion was made to switch to using
DrawText
withDT_CALCRECT
.I made the change and now things look good again:
In the process of investigating I also discovered that despite the documentation,
GdiDrawText
does not return:even if DT_CALCRECT flag is set. I had no idea how you wanted to handle that, so I left it as is.