measuring SWT / JFace column header padding size - swt

I have a number of tables in an eclipse SWT application. They are Table/TableViewer tables and consist of a header, a row down the left with text and a series of graphics going across. There are 32 columns other than the text column, numbered from 0 to 31.
On Windows 7 and XP in classic mode, the text is fine, but in XP normal mode, they are truncated so they appear to go 0 1 2 3 4 5 6 7 8 9 1. 1. 1. 1. 1. etc. There is clearly enough room for the text either way.
If I just set the default width to 28 instead of 25, as I found it, they are then fine, but obviously that isn't very good as then I need more room for the interface in Windows 7 and XP Classic, where it was already ok.
I tried getting average width from fontmetrics but the text comes back as 5, in all modes. I can't find any way of either reducing of the padding (which would be the best way), or finding out how much padding there is (which would do). Do I need to draw the column headers manually?
ps: Sorry for the JFace / SWT, have only just started with this and not clear on the differences yet!

Calling TableColumn#pack() should give a column exactly the width it needs to display its content without wasting any space or truncating its content. This includes the column's header text.

You should use the TableLayout for a more dynamic size calculation of your table headers. A good starting point is the following blog article: http://eclipsenuggets.blogspot.com/2007/11/one-of-less-prominent-novelties-in.html

Related

MS Access - Right Align Formatted number on a Form

If I use Standard format for a number in a control then I can Align Right and it appears on the far right of the control in the Form. However, I am using numbers in millions and so want to format the number so that, for example, 50,123,456 will appear as 50.123. So I use format #,,.0 with decimal places set to 3. If I set alignment to left, it aligns to the left of the field on the form, Align Center and it appears in the center. But Align Right and there is a large space to the right of the number, like padding. Is there a way to get the formatted number to hit right up to the right side on the form?
Replace the ControlSource with the expression:
[Amount]/1000
Set property Format to: Fixed
Set property DecimalCount to: 0
The formating option might not be the right approach to getting the needed solution. Do the following instead
Put the format to general number.
Put the decimal places value to 0.
Then go to VBA and add the following code to the after update event of the control
Private Sub allocatedamount_AfterUpdate()
Me.allocatedamount = Left((Me.allocatedamount / 1000000), 6)
End Sub
In this case i added the code to the after update evnt of the control on the form named allocatedamount
I have attached two images.
This code will work for numbers between 10 million and 99 million, where it is between 100 million and 999 million you will have to add another zero to the constant 1000000 used in the VBA code,so that will entail using an If statement to first determine if the value is between 10 million and 99 million or 100 million to 999 million.

How do you auto size columns of a grid for PDF format in Birt reporting

I am working on a report in Birt reporting using Birt 4.5 in eclipse.
I have a grid that has 3 columns and inside each column is a label with some hard coded value to give you a test scenario,I also set the "Can shrink" property to true, and I did change the layout Preference to auto-Layout, see pic bellow.
Now when I run this example as a Html out of eclipse I get the following and it works exactly like I want it to. It auto sizes the columns so the first column size has increased and the last 2 decreased.
Html pic :
Now I actually want it as a PDF format but the columns doesn't auto resize.
PDF pic :
I want this functionality because my report is going to be dynamic.
Is it possible to get the same result in the pdf format as html? If it is what properties should I set or how do I accomplish this?
No, this is not possible.
Those columns with no width specified (in your example: all three) take the remaining width (after considering the columns with a specified width) to equal parts.

itext component over another component

I'm creating a pdf report with itext and I'm having a problem. I create a line separator and immediately below I create a pdfTable. The problem is that de top border of the table is over the line separator I just created. Is any way to down a couple of lines in order to draw the next component with itext and solve this?
Thank you
Please take a look at the API documentation of the PdfPTable class. You'll fond methods such as setSpacingBefore(float spacing) and setSpacingAfter(float spacing). In you case, you could something like:
table.setSpacingBefore(6);
This will introduce a spacing of 6 user units (which by default corresponds with about 1/12 of an inch) before the table.
The spacing you need for "a couple of lines" depends on the leading. The default fonts size is 12 and the default leading is 1.5 times the font size. Two lines would be (2 x (12 x 1.5)) or 36 user units (about half an inch).

D3 Stacked Bar Chart outer padding

I've been working on adapting the stacked bar chart example (http://bl.ocks.org/mbostock/1134768). The problem I'm having is that there's
always outerpadding. The API lists the outer padding as a 3rd option, but omitting
it or setting it to 0 still leaves some padding. In most cases, it isn't too bad,
but with large data sets it tends to be a huge amount of padding. For all the code
relevant to my issue, you can check the link above. It's not very noticeable in that
example, but the first bar isn't drawn until about 12 pixels (in larger data sets I'm using
this can be at 100 or more pixels); I want it to start at 0 pixels.
Thanks! If you need any more explanation just let me know and I'll do my best.
EDIT: After testing, it appears rangeBands() starts at 0, but I'm still not sure why the rounding
from round bands would round as much as it did. Oh well, I can deal with using rangeBands.

FreeType2: Get global font bounding box in pixels?

I'm using FreeType2 for font rendering, and I need to get a global bounding box for all fonts, so I can align them in a nice grid. I call FT_Set_Char_Size followed by extracting the global bounds using
int pixels_x = ::FT_MulFix((face->bbox.xMax - face->bbox.xMin), face->size->metrics.x_scale );
int pixels_y = ::FT_MulFix((face->bbox.yMax - face->bbOx.yMin), face->size->metrics.y_scale );
return Size (pixels_x / 64, pixels_y / 64);
which works, but it's quite a bit too large. I also tried to compute using doubles (as described in the FreeType2 tutorial), but the results are practically the same. Even using just face->bbox.xMax results in bounding boxes which are too wide. Am I doing the right thing, or is there simply some huge glyph in my font (Arial.ttf in this case?) Any way to check which glyph is supposedly that big?
Why not calculate the min/max from the characters that you are using in the string that you want to align? Just loop through the characters and store the maximum and minimum from the characters that you are using. You can store these values after you rendered them so you don't need to look it up every time you render the glyphs.
I have a similar problem using freetype to render a bunch of text elements that will appear in a grid. Not all of the text elements are the same size, and I need to prerender them before I know where they would be laid out. The different sizes were the biggest problem when the heights changed, such as for letters with descending portions (like "j" or "Q").
I ended up using the height that is on the face (kind of like you did with the bbox). But like you mentioned, that value was much to big. It's supposed to be the baseline to baseline distance, but it appeared to be about twice that distance. So, I took the easy way out and divided the reported height by 2 and used that as a general height value. Most likely, the height is too big because there are some characters in the font that go way high or way low.
I suppose a better way might be to loop through all the characters expected to be used, get their glyph metrics and store the largest height found. But that doesn't seem all that robust either.
Your code is right.
It's not too large.
Because there are so many special symbols that is vary large than ascii charater. . view special big symbol
it's easy to traverse all unicode charcode, to find those large symbol.
if you only need ascii, my hack method is
FT_MulFix(face_->units_per_EM, face_->size->metrics.x_scale ) >> 6
FT_MulFix(face_->units_per_EM, face_->size->metrics.y_scale ) >> 6