I have a document in which a line of text must always be the same physical length regardless of the content of the line using a variable length font. The font and font size is known. The field is underlined. I need to determine the number of non-breaking spaces I need to add to the end of the line of text so its length is constant. For example, if I wish to generate an underlined field of text in 10.5 pt Times New Roman in which the text is centered, how do I calculate the number leading spaces and right-filled non-breaking spaces to the length of the field is always 2.0 inches regardless of whether the underlined text is “California” or “Iowa”? I know I have 144 points in 2 inches. What I do not know is how to compute the points length of both a space and a word/phrase whose contents varies
Constant text length and variable pitch font are contradictory. Formatting text with non-breaking spaces means you have not understood how text processors work.
If your goal is to create a centered heading, create a user paragraph style with attributes center, requested font face and size. Assign this style to your heading paragraph. Writer will do the positioning math.
For other layouts, describe the purpose and we’ll hint at solutions.
For an introduction to Writer features, read the Writer guide.
I think I have not conveyed the problem precisely. The issue is not constant text length but constant line length. I am using a python-based add-on to LibreOffice that can pull elements from a database and create a conditional-variable field which is underlined whose placement and line length is always 2 inches. To do so, I need to obtain the point length of the database element when it is rendered in a particular font and font size.
I need a library that I can access from Python that contains a function I can call with the text data element, font name and font size as arguments, which will return the length of the text data in points or some other unit of measure, the number of which in a given standard of length (inches, cms) is known.
In that way, I can generate a Python text conditional variable that, when placed into the document will always occupy a specific position and visual field length in the document.
I still don’t see the final goal. Could you attach a sample file or show a screenshot of some example you already have?
I feel that either you use the wrong tool (i.e. Base is the component for interfacing a database and it has a sophisticated report generator), or you are blinded by your idea about conditional variable.
A constant “element” length can be achieved with a frame (and fine-grained controlled with a frame style).
Thank you for taking the time to comment. I have found the function I need. By importing the Python module ctypes and calling the windll library, I can get the precise length of any arbitrary text in points and create the necessary variable to place in the document such that its position and visual field length is what is required.
This technique is generally only required when the text is underlined. Otherwise, simply place the text at whatever starting location in the document is required is sufficient.
If your problem is solved, please mark the appropriate post as the solution. Thanks.
Does it mean the underline extends to the “line” limits, not only text? In this case a much simpler approach it to use an adequate paragraph bottom border. You don’t need to add any spurious NBSP since a border is not related to paragraph text but to the paragraph bounding rectangle.
All you have to do is configure the paragraph style for your “line” and assign it. No macro, no programming, no trigger for the macro. Fully automatic and much more efficient.