10-10-2016 08:26 AM
Hello, I wish to measure the length of text in order to establish how much of the text will fit on a single line of title space in a (fixed-width, namely 800px) ODS graphic. The measurement solution should work ideally for different fonts and font styles and certainly for different font sizes. As an example, the pieces of text below each fill up a single line of title space in my graphics pretty much exactly (differences as measured on-screen with a ruler are insignificant). I measured these pieces of text using Java (SwingUtilities.computeStringWidth()), and the differences that it gives me are significant compared to what I'm seeing in the graphics, so I concluded Java and SAS must be rendering the fonts differently.
Arial bold 9pt:
Very long title Very long title Very long title Very long title Very long title Very long title Very long title Very long title V..
Length returned by Java: 548 (no idea what unit)
Arial bold 9pt:
Length returned by Java: 489
Arial bold 12pt:
Very long title Very long title Very long title Very long title Very long title Very long title Ve...
Length returned by Java: 504
Arial bold 12pt:
Length returned by Java: 533
Does anyone know how to measure text as rendered by ODS for PNG output? Oh yes I'm using SAS 9.2 in case that's relevant. Advice gratefully received - thanks!
10-11-2016 10:56 AM
You are likely going to spend a lot of time and frustration to arrive an any "generic" font size control option. First which graphing procedures are you using? And which options. To a certain extent the title area is affected by the space used by the left an righ axis. So if you have longer text such as values like 100,000 as axis labels you have less remaining space than for values that top out at 100. Also if the Y axis labels "wrap" to two "lines" of text that is less space.
Another issue will relate to settings that affect your graphics such as which ODS destination and the DPI resolution set for the destination. Note tha PX is a display device measurement and not a FONT size unit.
Also you run into the issues of proportional fonts. If you run your test with a line of 80 capital "W" and 80 lower case "i" you may note that the latter comes in noticeably shorter for the same font.
10-12-2016 04:23 AM
I'm using SGRENDER to render GTL templates. The destination is LISTING at 300 DPI. This is all hidden within a macro system, and there is an in-house style which the system uses by default where the font for titles is Arial bold 9pt, although the macros have a parameter which allows users to change the font size and there is a parameter which allows users to override the default style with any other style.
I certainly accept what you say in that I may be aiming for a moving target. However my thinking now is I can get probably away with "fixing" the target by restricting the support for long titles (which is what my remit is - to build into the system handling of titles > 256 chars provided by the user via a macro variable and split the title text into multiple ENTRYTITLEs such that there is no trailing whitespace except on the final ENTRYTITLE for the given piece of title text) to the default (and most common for the users) scenario with the default font and single-line Y-axis labels etc. So given a fixed and known amount of title space available, this should be feasible to implement assuming I have a reliable way of measuring the length of text as rendered in a (or in my case - the) given font in the first place.
In the meantime I have a workaround in that I have a list of the relative widths of ASCII chars 33-126 for Arial 12pt which I can probably make use of. I don't know what the unit is but that doesn't matter. I can use this to measure the amount of title space I have to play with plus build in a safety margin. It would be good though to have a more scientific approach!
Thanks for your response :-)