If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
drawing strings and character position problem
2 posts
• Page 1 of 1
drawing strings and character position problem
I'm attempting to make a TurboPascal-styled code editor for the Custom DSPcode project. However, I run into two problems.
The actual character height (the hight of a line - the actual size of the character is irrelevant) does not match with font size and I also can't find the width-to-height ratio for one character. I'm using Courier New (a monospaced font).
measureString method is also not reliable - it calculates rectangle where text is drawn (from first drawn pixel to the last one)- not the area that monospace characters actually occupy (including empty pixels at the bottom and sides of the characters).
My goal is to draw a text onto a grid, where raws align and then use x,y coorinates on that grid to specify cursor position. But without a way to properly align text and the grid (by knowing the space each char occupies) it is impossible.
Only workaround I can think of is to split the text into individual characters and draw them onto the grid precisely one by one. However, I'd like to not do so, because it takes quite long (cpu spikes, gui freezing etc.)
The actual character height (the hight of a line - the actual size of the character is irrelevant) does not match with font size and I also can't find the width-to-height ratio for one character. I'm using Courier New (a monospaced font).
measureString method is also not reliable - it calculates rectangle where text is drawn (from first drawn pixel to the last one)- not the area that monospace characters actually occupy (including empty pixels at the bottom and sides of the characters).
My goal is to draw a text onto a grid, where raws align and then use x,y coorinates on that grid to specify cursor position. But without a way to properly align text and the grid (by knowing the space each char occupies) it is impossible.
Only workaround I can think of is to split the text into individual characters and draw them onto the grid precisely one by one. However, I'd like to not do so, because it takes quite long (cpu spikes, gui freezing etc.)
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: drawing strings and character position problem
Totally missed that post, sorry!
A font is constructed from measurements. It all starts with the base line, where all glyphs "sit on". From there, a bunch of values describe different heights and widths, which finally make up the complete size. There's ascent, descent, internal leading, external leading, bearing, etc. If interested, google for "font metrics" and "typography".
You could access font metrics using GDI/GDI+. However there's also a quick Ruby solution to your specific problems. Hope it helps!
EDIT: Updated file to an even better version
EDIT 2: For some reason, I reuploaded the old version Hopefully this time it's the right one
A font is constructed from measurements. It all starts with the base line, where all glyphs "sit on". From there, a bunch of values describe different heights and widths, which finally make up the complete size. There's ascent, descent, internal leading, external leading, bearing, etc. If interested, google for "font metrics" and "typography".
You could access font metrics using GDI/GDI+. However there's also a quick Ruby solution to your specific problems. Hope it helps!
EDIT: Updated file to an even better version
EDIT 2: For some reason, I reuploaded the old version Hopefully this time it's the right one
- Attachments
-
- char_width_line_height.fsm
- correct version. use this.
- (774 Bytes) Downloaded 811 times
-
- char_width_line_height.fsm
- wrong version
- (899 Bytes) Downloaded 791 times
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 34 guests