|
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. |