Is there a relation between a typography's character width and character height - python-3.x

I encounter a problem when i use python-pptx, i need to put a line of text to a fixed width textbox and keep it in one line, so i have to calculate the proper font size manually.
The problem is that the font size is determined by character's height, not its width, and i have not found out the relation between its height and width. Can anyone help me out?

The width of a string in pixels will be approximately some value depending on the text, multiplied by the font size. Approximately, because there may be jumps. A 12 point font might have the exact same width as 11 point, and 13 point might be wider. You might be able to choose 12.4 points which depending on the implementation might be wider or not wider than 12.3 or 12 point.
I suggest that you start by making a wild guess about the best font size based on the length. Sure, WWWWW is a lot wider than iiiii, but for average text it works. You measure the width, then you make a better guess for the best font size.

Related

Setting ONLY WIDTH of a figure size, without height (Python)

I want to have a figure which is limited to the given size in width but its height is not set and is free to change.
The goal here is to define a figure which has a certain width but can change its height depending on the number of the variables that will be shown in the legend. Meaning, if we have more variables to show in legend, then the figure height will automatically adjust itself by getting longer (I am implementing a specific-sized border from all 4 sides, therefore, fixing figure height would crush the legend into the bottom of my subplots).
Of course I tried and just removing one component from figsize will not work (Figure1 = plt.figure(figsize=(8)) gives an error).

Is it possible to scale a text to a certain width by changing font attributes?

Let me add an image to describe my question.
http://i.stack.imgur.com/SisN7.jpg
My facebook name is located at the top-left. It has 9 characters and it is centered on the dark gray block.
Right now, if my name was just "D", it would appear on the place where "D" letter is located. Alternatively, if my nickname was something like "IHaveAVeryLongUsernameWoah", it would overflow to pink area.
Is there any auto-scaling feature on FabricJS, so I can simply define the max-width, and FabricJS calculates font size automatically?
Like, if there is a single letter, print it at the center. If there are alot of letters and letter width exceeds maximum size, then lower font size.
Not sure if this is doable. Any help would be appreciated.

Fiji/ImageJ - Measure tool when x and y resolution of image not equal

I have images with unequal resolution in x and y direction. The pixel height is larger than the pixel width. The pixel width and pixel height are saved in Image > Properties.
When I draw an ellipse on the image and try to use the Analyze > Measure tool I get a '0' for both major and minor axis length for the "Fit ellipse" measurement.
I can only get a proper measurement if I remove the scale of the image, or manually change the pixel height and pixel width to an equal number.
I assume this is a bug, but maybe I'm missing something?
As a workaround I was thinking of writing a small macro that saves pixel height and pixel width, then removes the scale of the image, then measures major and minor axis length in pixel and then re-applies pixel height and pixel width to the measurements.
But I can't find the command for reading out the resolution. Any pointers?
The documentation for the Set Measurements... command states in the description of the Fit ellipse parameter:
Note that ImageJ cannot calculate the major and minor axis lengths if
Pixel Aspect Ratio in the Analyze▷Set Scale… dialog is not 1.0.
Your workaround should work, just use the getPixelSize(unit, pixelWidth, pixelHeight) macro function.

Can an Enum be used to provide two values?

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.

AI is not giving actual text height

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.

Resources