drawing strings and character position problem
Posted: Mon Feb 16, 2015 6:02 pm
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.)