|
From: Carlos d. M. <cg...@wo...> - 2002-08-03 22:08:11
|
I want create a bitmap for hold a text string loaded from a file. I have a fixed width, given by the window, but the height depends on the string length, but I don't see any function in the win32 reference which could be used for achieve it in a simple way. Though in it is claimed that the result is width and height GetExtentPoint32 gives the dimensions of the string without considering that it will be displayed in multiple lines, so it gives a lpsize which has the cx length of all the characters of the string and the height of a single line. If I try to work with it in the simple ways (cy = cx /window widht * text height) I get a too short height (it seems to consider newlines as single characters or unextended ones), but if I try to calculate how many newlines are for adding more height I get a bitmap which is still either too long or too short. The book I am read is not useful, because it does not use the way I use, and when it treates about scrolling text hey have a simple example: they have only many short lines, so they know easily the height, and they know that no string will be truncated. If I try to calculate with the MaxCharWidth the chars per line and then calculate the height I still have the bitmap with a size that is too short if the amount of newlines is high. (not solved if then I add a new tmHeight per each newline). Is there some simple way to do what I intend? |
|
From: Abhijit S. <mu...@gm...> - 2002-08-04 09:06:08
|
Greets, Carlos.
> I want create a bitmap for hold a text string loaded from a file. I have
> a fixed width, given by the window, but the height depends on the string
> length, but I don't see any function in the win32 reference which could
> be used for achieve it in a simple way. Though in it is claimed that the
> result is width and height GetExtentPoint32 gives the dimensions of the
> string without considering that it will be displayed in multiple lines,
> so it gives a lpsize which has the cx length of all the characters of
> the string and the height of a single line. If I try to work with it in
> the simple ways (cy = cx /window widht * text height) I get a too short
I think this should be
cy = (cx / window_width + 1) * text_height
since for cx/window_width == 0, there is actually one line already (for
example, 300/400 is 0, but there is one line of width 300 units). You might
also want to have a variable for line spacing.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|
|
From: Carlos d. M. <cg...@wo...> - 2002-08-04 18:02:57
|
Abhijit Shylanath escribi=F3: > Greets, Carlos. > > > I want create a bitmap for hold a text string loaded from a file. I h= ave > > a fixed width, given by the window, but the height depends on the str= ing > > length, but I don't see any function in the win32 reference which cou= ld > > be used for achieve it in a simple way. Though in it is claimed that = the > > result is width and height GetExtentPoint32 gives the dimensions of t= he > > string without considering that it will be displayed in multiple line= s, > > so it gives a lpsize which has the cx length of all the characters of > > the string and the height of a single line. If I try to work with it = in > > the simple ways (cy =3D cx /window widht * text height) I get a too s= hort > > I think this should be > > cy =3D (cx / window_width + 1) * text_height > > since for cx/window_width =3D=3D 0, there is actually one line already = (for > example, 300/400 is 0, but there is one line of width 300 units). You m= ight > also want to have a variable for line spacing. > Yes, I tried that, but the bitmap result has more than a line of differen= ce, there is a text with many newlines, and the bitmap is less than the half = of the size needed, although with a new modification I achieved to have in most = cases bitmaps which are more than a 15% longer than text. I considered the tmExternalLeading but it is zero for the font I use (the default). I got the solution, it is easy but not the most I'd like. I don't know ho= w I could not think it, well I know, it sem to me at first as a too tedious w= ay for be accepted, but now I am thinking it would be no so. It consists in writ= e a function which will know the number of characters per line (I can use the average widht of the actual string, simply divide cx by strlen), calculat= e how many letters will be needed for reach a decent distance from the right en= d of the window and substitute the nearest space by a newline (drawtext unders= tands \n), so with that and the newlines which are yet in the string I can now exactly how many lines will have the text. [Some time after] I noticed that in the countlines function I wrote \n as newline, but then= I remembered that in windows end of line is \r\n, and each \r, as seen at a little experiment, makes the next line be spaced one line more, so I chan= ged that, \n by \r, and either I considered tabs (I've right now see that I h= ad to bother with them), so it returns one line per each \r and per each \t, an= d three per each \v, and I added the function that receiving the number of = chars per line and the lenght of the string goes over it counting char-per-line= so adding a line each time it reaches a substring between newlines greater t= han the charsper-line, and adding more per multiplication of the charperlines value. Now this works fine for some files (bitmaps with just one or two l= ines longer than text), but I still find some which still is the bitmap too sh= ort, and one of them is as an html just that the first I tried as example of t= ext, it has the same apparent amount of tabs and newlines (note that I use the= html as plain text, I not interpret the tags, they simply stay there <HTML>, e= tc), and for it the bitmap is even shorter in proportion than the other of the special file with great amount of tabs and newlines. Perhaps there is som= e spacing character I miss?. \r \n \t \v are what I know or remember. And s= till I am adding the tabs twice, and each time I treat them as a newline. I shou= ld have too large bitmaps instead of having too short. Thanks for the help, and sorry for the little stupid question. |
|
From: Carlos d. M. <cg...@wo...> - 2002-08-05 12:03:45
|
Done! I wrote a new function for calculate the lines (one which uses a very better strategy of programming, more compact and all those things that shall be done), and although this is not supoosed to count tabs more than once, than the previous functions used (the new function makes the work of the two previous, which did one of the three counts twice, once per function), it makes bitmaps with a very well adjusted size. If before the height was just the needed, more than a 15% longer or more than 20% shorter, now it is constantly less than a 3% longer. |