I'm creating a panel in which dynamic strings are shown. I want to resize automatically the panel in order to avoid to see truncated strings (that are not hard coded so I can't know dimensions in advance).
So, given a string, the font weight, name and size, is possible to calculate the bounding box dimension in pixels, so I an use these data to recalculate dimensions of my panel?
Related
There are multiple rectangular areas in the 2d-numpy array. All the rectangular areas have value 1, other areas are zero. I want to extract a minimum number of rectangular connected components from the numpy array. These connected components can touch each other in any direction.
I tried extracting connected components using label function from scipy.ndimage.measurements but it assigns the same label to rectangles which touch each other.
I also tried, morphological opening but I do not want to lose the original shape of the rectangle.
The image shows the expected output for a better understanding of the problem.
Is there a better way to extract a minimum number of perfectly rectangular regions?
In my SVG picture there are some text labels that are displayed dynamically in top part of the image. In some cases (i.e. smaller screen size, bigger font size), they partially disappear outside the vievBox (like if overflow: hidden; was set) - see the picture (the long word in the middle is the overflowing label).
My idea is to scale down the image so that the labels are visible. How to achieve this?
In my case, I had quite wide bottom margin, so I could afford moving the whole image down to uncover the top part.
Final solution was wrapping the whole image with <g transform="translate(0,10)">.
The first value refers to left-right movement, the other one to up-down (positive values move the image down, negative - up).
I created a custom venn chart for two sets an their intersection in JavaFX.
Now I want to show the number of elements in this sets like in the following picture:
The sets are ellipses and I used masks to give the intersection a different color.
Now I want to show the number with size and position related to the available space so that the numbers are always inside the according area.
The width for the text element is easy to calculate, but I don't know how to get available height for the text elements.
Maybe it could be helpful to have the pixels of the ellipses as path, but I have no idea to how I can get this.
Does anyone know how to implement that?
Edit:
I developed an algorithm to find the size of a rectangle, which fits in the required areas of the ellipses. The text are scaled to the size of the rectangle and it works, but now I have another problem.
I need to center the scaled text in the rectangle an I used a StackPane for that. But I can't position the StackPane in the chart parent. If I set the layoutX and layoutY the bounds in parent are different.
For example: stackPane with text = sp;
sp.setLayoutY(122.1662320906945);
The Result for getBoundsInParent().getMinY() is 97.16622924804688;
How can I set the StackPane position, if I use it in a chart class as chart children?
For drawing filled shapes like Rectangle, Eclipse need two values width and height (converted from int to float).
There's an enum,
Public enum Sizes : int
{
One=5,
Two=10,
Five=10,
Seven=12,
Ten=15,
}
In terms of drawing a Square of One, should be of width and height of 5. Which is straight forward. However when drawing Oval Shapes and Rectangular shapes above one value isn't sufficient.
Is there a way I could define another float value? So when compared for Ten, it can provide 15 for Width and 10 for Height...
Or does it mean, there should be two enums, one for Width and one for Height?
EDIT to provide more background info:
There's an UI which allows users to create certain shapes.
User inputs are: Shape Type (Line, Rectangle, Eclipse), Points, Size (but this size doesn't exactly reflect the size of the shape. e.g. 10 is a capacity. Capacity 10 must draw 15px Width and 10px height Rectangle/Eclipse).
Line doesn't take Size into account as it is drawn using the Points input. The rest of the shapes do take Size into account. So this is where I need to check the Size(capacity) parameter and issue the correct Width and Height to be drawn.
I want to calculate actual height of the text, but the AI is giving the text height using the bounding box dimensions.
Please help me to calculate actual height of text!!
Thanks
This is not possible with SVG. You might have to use a (hidden) <canvas> element, draw the text there and check what pixels were colored. Have e.g. a look at the simple contextBoundingBox() function by Phrogz.