sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 641 forks source link

SharpDX Toolkit SpriteBatch.DrawString issue #236

Closed xanather closed 10 years ago

xanather commented 10 years ago

Spritebatch seems to be drawing/measuring letters that are 1 pixel in width incorrectly.

For example (textbox from within my game):

badletters

Compiled font file used (generated by tkfont.exe) http://www.xanather.com/Main.font.zip

This issue only happens if characters such as "i", "I" (upper case i) and "l" (lower case L) are the first letters in the string. Any of them characters that are not at index zero will be measured correctly.

This is the only actual issue that Ive had with SharpDX toolkit after moving over a large code base from MonoGame. Amazing!

RecursiveCall commented 10 years ago

I can confirm this. Also, the space (" ") returns font.MeasureString().X value of 0. In XNA, it would return the actual width of the space (I'm guessing based on whatever the maximum character block would be).

ghost commented 10 years ago

This is not related to the actual topic, but: @xanather may i ask how you are doing this red outline rendering? do you just offset it 4 (or 8) times when before drawing the black font? or do you have some shader in place?

xanather commented 10 years ago

I first draw the red outline (4 drawstring calls) at offsets (-1, 0), (1, 0), (0, -1), (0, 1) and then draw the black text over it (no offset).

xanather commented 10 years ago

https://github.com/sharpdx/SharpDX/blob/master/Source/Toolkit/SharpDX.Toolkit.Graphics/SpriteFont.cs#L402 Is this the issue? I have a feeling its not the actual imported Glyph measurements since all characters can be drawn/measured fine IF they are not the first character.

xanather commented 10 years ago

Any thoughts as to why this might happen? Its the only bug ive found on SharpDX TK and I rather would not code around it.

xoofx commented 10 years ago

I had no time to look into this. This code is inherited from SpriteFont from DirectXTk. If you take the time to dig into this issue and fix it that would be helpful

xanather commented 10 years ago

Well I do owe this project alot, I will give it a shot. This is also a time for me to solve the requirements on compiling on Windows 7.

xanather commented 10 years ago

Edit: I was copying over the Input library instead of the Graphics library, silly me :) Should have fix soon

xanather commented 10 years ago

Issue stems from the change at https://github.com/sharpdx/SharpDX/issues/86 https://github.com/sharpdx/SharpDX/commit/060f9b7363e55959a75a27066b9cfa70e3fa4fe7

xoofx commented 10 years ago

Thanks, I did some tests but the fix was not working well with fixed fonts and spaces at the beginning of the line. After checking and using the same rule as DirectXTk, It is working well with fixed font like "Courier New" as well as "Arial". Let me know if there is still an issue

xanather commented 10 years ago

Edit: going to make another issue.