Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Finding the leftmost pixel in a piece of text when using GDI+

Reply
Thread Tools

Finding the leftmost pixel in a piece of text when using GDI+

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      06-28-2005
I am using GDI+ to generate buttons in my application. Because I want the
left and right edges of the buttons to be a certain number of pixels from
the start and end of the text, I need to know (or be able to calculate) the
left and rightmost pixels of the text. However, this is a problem because
not all letters have their leftmost pixel at the same X position. For
example, when using the following font:

Dim buttonfont As New Font("Arial", 19, FontStyle.Bold, GraphicsUnit.Point)


and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i - 64)
* 20)

Next


The characters 'A' and 'J' start 2 pixels farther to the left than most
other characters (there are also a couple other characters that are offset
by 1 or 2 pixels). Is there any easy way to determine what X position the
first and last pixel of a character is at? Because this depends on the font,
the only way to do it manually would be to test each pixel. Is there a
method that can be used to do this? Thanks.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      06-28-2005
If this is an offline process, testing each column of pixels should be
enough.

You could also try
http://msdn.microsoft.com/library/de...ntext_52at.asp
and in particular the GLYPHMETRICS structure that should allow to get the
"box" in which the character is drawn...

Patrice
--

"Nathan Sokalski" <(E-Mail Removed)> a écrit dans le message de
news:OCD%(E-Mail Removed)...
> I am using GDI+ to generate buttons in my application. Because I want the
> left and right edges of the buttons to be a certain number of pixels from
> the start and end of the text, I need to know (or be able to calculate)

the
> left and rightmost pixels of the text. However, this is a problem because
> not all letters have their leftmost pixel at the same X position. For
> example, when using the following font:
>
> Dim buttonfont As New Font("Arial", 19, FontStyle.Bold,

GraphicsUnit.Point)
>
>
> and using the following lines to draw text:
>
> For i As Integer = 65 To 90
>
> testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i -

64)
> * 20)
>
> Next
>
>
> The characters 'A' and 'J' start 2 pixels farther to the left than most
> other characters (there are also a couple other characters that are offset
> by 1 or 2 pixels). Is there any easy way to determine what X position the
> first and last pixel of a character is at? Because this depends on the

font,
> the only way to do it manually would be to test each pixel. Is there a
> method that can be used to do this? Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
>



 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      06-28-2005
Do you know of anywhere where I can see an example? Thanks.
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"Patrice" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If this is an offline process, testing each column of pixels should be
> enough.
>
> You could also try
> http://msdn.microsoft.com/library/de...ntext_52at.asp
> and in particular the GLYPHMETRICS structure that should allow to get the
> "box" in which the character is drawn...
>
> Patrice
> --
>
> "Nathan Sokalski" <(E-Mail Removed)> a écrit dans le message de
> news:OCD%(E-Mail Removed)...
>> I am using GDI+ to generate buttons in my application. Because I want the
>> left and right edges of the buttons to be a certain number of pixels from
>> the start and end of the text, I need to know (or be able to calculate)

> the
>> left and rightmost pixels of the text. However, this is a problem because
>> not all letters have their leftmost pixel at the same X position. For
>> example, when using the following font:
>>
>> Dim buttonfont As New Font("Arial", 19, FontStyle.Bold,

> GraphicsUnit.Point)
>>
>>
>> and using the following lines to draw text:
>>
>> For i As Integer = 65 To 90
>>
>> testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i -

> 64)
>> * 20)
>>
>> Next
>>
>>
>> The characters 'A' and 'J' start 2 pixels farther to the left than most
>> other characters (there are also a couple other characters that are
>> offset
>> by 1 or 2 pixels). Is there any easy way to determine what X position the
>> first and last pixel of a character is at? Because this depends on the

> font,
>> the only way to do it manually would be to test each pixel. Is there a
>> method that can be used to do this? Thanks.
>> --
>> Nathan Sokalski
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>
>>

>
>



 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      06-29-2005
Try around :
http://cvs.sourceforge.net/viewcvs.p...rm1.cs?rev=1.2

I've done a search using gmBlackBoxX (you could use any other name that
belongs to this structure) on Google...

Good luck.

--
Patrice

"Nathan Sokalski" <(E-Mail Removed)> a écrit dans le message de
news:%(E-Mail Removed)...
> Do you know of anywhere where I can see an example? Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Patrice" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > If this is an offline process, testing each column of pixels should be
> > enough.
> >
> > You could also try
> >

http://msdn.microsoft.com/library/de...ntext_52at.asp
> > and in particular the GLYPHMETRICS structure that should allow to get

the
> > "box" in which the character is drawn...
> >
> > Patrice
> > --
> >
> > "Nathan Sokalski" <(E-Mail Removed)> a écrit dans le message de
> > news:OCD%(E-Mail Removed)...
> >> I am using GDI+ to generate buttons in my application. Because I want

the
> >> left and right edges of the buttons to be a certain number of pixels

from
> >> the start and end of the text, I need to know (or be able to calculate)

> > the
> >> left and rightmost pixels of the text. However, this is a problem

because
> >> not all letters have their leftmost pixel at the same X position. For
> >> example, when using the following font:
> >>
> >> Dim buttonfont As New Font("Arial", 19, FontStyle.Bold,

> > GraphicsUnit.Point)
> >>
> >>
> >> and using the following lines to draw text:
> >>
> >> For i As Integer = 65 To 90
> >>
> >> testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i -

> > 64)
> >> * 20)
> >>
> >> Next
> >>
> >>
> >> The characters 'A' and 'J' start 2 pixels farther to the left than most
> >> other characters (there are also a couple other characters that are
> >> offset
> >> by 1 or 2 pixels). Is there any easy way to determine what X position

the
> >> first and last pixel of a character is at? Because this depends on the

> > font,
> >> the only way to do it manually would be to test each pixel. Is there a
> >> method that can be used to do this? Thanks.
> >> --
> >> Nathan Sokalski
> >> (E-Mail Removed)
> >> http://www.nathansokalski.com/
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re.sub(): replace longest match instead of leftmost match? John Gordon Python 13 12-20-2011 02:58 AM
Download a file piece by piece Patrick Plattes Ruby 2 11-30-2006 07:48 PM
Finding the leftmost pixel in a piece of text when using GDI+ Nathan Sokalski ASP .Net Building Controls 3 06-29-2005 09:19 AM
Finding the leftmost pixel in a piece of text when using GDI+ Nathan Sokalski ASP .Net 3 06-29-2005 09:19 AM
leftmost longest match (of disjunctions) Joerg Schuster Python 12 12-03-2003 12:37 PM



Advertisments