From: "Dhanuja B." Date: 2011-12-09T04:32:23+09:00 Subject: Re: Truncation using Pixels Thanks Jeremy for the reply. We need the truncation method to display the text in the browser. It should support the widely used browsers. Example1: This is a long piece of text which will need to be truncated Example1: THIS IS A LONG PIECE OF TEXT WHICH WILL NEED TO BE TRUNCATED In Display, the column width will be less and the text needs to be truncated. Expected Result1: This is a long... Expected Result2: THIS IS A LON... Result when character truncation is used: THIS IS A LON G... To avoid this, we need to use truncation based on pixels. Thanks in Advance, Dhanuja Jeremy Bopp wrote in post #1035630: > On 12/07/2011 12:40 PM, Dhanuja B. wrote: >> Is there any method available to truncate string based on Pixels in >> Ruby? > > I'm not aware of any built-in method to do this, and I suspect it will > depend greatly on how exactly you're trying to render the string to the > display device. For instance font selection and point size are probably > the biggest factors that determine the rendered representation of a > string, and those are generally variable. The tools available to you to > figure out the string size in pixels almost certainly varies depending > on the library or framework you're using to handle the actual work. > > So, first of all, how do you plan to render your strings, disregarding > the overall length in pixels? Are you going to have them inserted into > a web page that is viewed by a browser, or are you using something like > GTK, QT, etc. as a conventional graphical user interface, or are you > doing something else? > > Can you provide an example of truncating strings the way you need in > another language? > > -Jeremy -- Posted via http://www.ruby-forum.com/.