Board index » cppbuilder » RichEdit's Text Length in pixels

RichEdit's Text Length in pixels


2004-01-09 08:44:25 AM
cppbuilder6
Is there an accuarate way to calculate the length in pixels
of the text (n lines) in RichEdit for any font (any Font Name
and Font Size)
TIA
Rodolfo
 
 

Re:RichEdit's Text Length in pixels

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
Quote
Is there an accuarate way to calculate the length in pixels
of the text (n lines) in RichEdit for any font (any Font Name
and Font Size)
If you want to query the height of multiple lines, then the only thing you
can do is calculate the beginning and ending offsets of the desired text,
translate the offsets to pixels (there are messages available for that), and
then query the difference in values.
Gambit
 

Re:RichEdit's Text Length in pixels

What do you mean by the text offset (or how do you measure it)?
Rodolfo
 

{smallsort}

Re:RichEdit's Text Length in pixels

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
Quote
What do you mean by the text offset
I mean the 0-based offset from the beginning of the content. Every
character in the text has an offset - the first character is 0, the next
character is 1, and so on to the end of the text. That offset can then be
translated into absolute pixel coordinates (and vice versa). There are also
messages available for determining the character offset of the beginnning of
individual lines in the text, and also to determine the lengths of thos
lines. By determining the beginning and ending offsets of the first and
last lines which you are interested in, you can then figure out how many
pixels those lines take up on the screen.
Gambit
 

Re:RichEdit's Text Length in pixels

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
news:3ffe0a11$ XXXX@XXXXX.COM ...
>What do you mean by the text offset

I mean the 0-based offset from the beginning of the content. Every
character in the text has an offset - the first character is 0, the next
character is 1, and so on to the end of the text. That offset can then be
translated into absolute pixel coordinates (and vice versa).
Which are the functions that do the translation?
There are also
Quote
messages available for determining the character offset of the beginnning
of
individual lines in the text, and also to determine the lengths of thos
lines. By determining the beginning and ending offsets of the first and
last lines which you are interested in, you can then figure out how many
pixels those lines take up on the screen.
I tried the approximate relationship
RichEdit1->Height = abs(factor*RichEdit1->Font->Height *
(RichEdit1->Lines->Count));
I added a factor to take into account the space between lines. Of course the
"factor"
is different for different fonts sizes and font types (Font names), which
makes it very difficult to
adjust. I have also assumed that all lines have the same height, which is
true in the my application.
Rodolfo
 

Re:RichEdit's Text Length in pixels

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
Quote
Which are the functions that do the translation?
There are no functions. They are all message-based operations. Look at the
following messages:
EM_POSFROMCHAR
EM_LINEFROMCHAR
EM_LINEINDEX
EM_LINELENGTH
Quote
I tried the approximate relationship
That will not work. The Font->Height property is not what you think it is.
Gambit
 

Re:RichEdit's Text Length in pixels

oki doki and thanks
"Computers don't die, they password away", Rodolfo
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Which are the functions that do the translation?

There are no functions. They are all message-based operations. Look at
the
following messages:

EM_POSFROMCHAR
EM_LINEFROMCHAR
EM_LINEINDEX
EM_LINELENGTH

>I tried the approximate relationship

That will not work. The Font->Height property is not what you think it
is.


Gambit


 

Re:RichEdit's Text Length in pixels

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
Quote
Is there an accuarate way to calculate the length in pixels
of the text (n lines) in RichEdit for any font (any Font Name
and Font Size)

Take look on:
www.codeproject.com/richedit/richeditsize.asp
Sort a strange but worked for me.
/Pavel
 

Re:RichEdit's Text Length in pixels

Thank you Pavel, I will try that as soon as I can.
Rodolfo
"Pavel Vozenilek" < XXXX@XXXXX.COM >wrote in message
Quote

"Rodolfo Frino - Macrosoft" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>Is there an accuarate way to calculate the length in pixels
>of the text (n lines) in RichEdit for any font (any Font Name
>and Font Size)
>
Take look on:
www.codeproject.com/richedit/richeditsize.asp

Sort a strange but worked for me.

/Pavel