Reconciling font etc. sizes between display and saved files

Q&A for C, C++, and/or C# developers using DPlot

Moderator: DPlotAdmin

Post Reply
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Reconciling font etc. sizes between display and saved files

Post by rkm »

Using DPlot Jr, in one application I'm creating a plot with the option of writing it to an image file from which it can be loaded by another application. Depending on the plot, it can be written as either a BMP or a PNG. In both applications the display windows for the plots are the same size (which I specify).

The problem is that, while the plots have the correct overall size, the text character sizes in the saved file are often substantially larger than those displayed in the program that generated that file. The results often include ugly overlapping text and other unprofessional appearing features in the saved file.

While I think I understand why this could happen for PNG files, I don't understand why it happens for BMP files. Is there something I could do to solve the problem? Or might it be a bug?
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Use a Size(width,height) command to specify the size of the box around the plot in inches. When you do that, font sizes (and line widths and pretty much everything that has a size associated with it) will be scaled if necessary so that fonts and other features are the same size relative to the plot as what you see on the screen.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

Is the Size(width,height) command in addition to the SetPluginImageDims(width,height) I'm using elsewhere to set the pixel dimensions of the plot written to file?

Does DPlot assume a standard pixels to inches conversion factor I can use in the Size(width,height) command?
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Is the Size(width,height) command in addition to the SetPluginImageDims(width,height) I'm using elsewhere to set the pixel dimensions of the plot written to file?
Yes.
Does DPlot assume a standard pixels to inches conversion factor I can use in the Size(width,height) command?
Yes, it uses the Windows "logical inches" setting, which is usually 96 dpi. But you can override that with SetPluginImageDims.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

I don't see how Size(state,X,Y,WYSIWYG) can meet my requirements.

My objective is to let DPlot automatically calculate the size of a plot such that it fills as much of the document window as possible( state = 0; X,Y, and WYSIWYG are ignored.)

but have DPlot adjust the font sizes used in the printed copy so that the printed copy is identical (as close as possible) to the displayed plot.

This seems to be the reverse of how Size() operates. According to the documentation if WYSIWYG is not equal to 0, then DPlot adjusts the font sizes used in the plot so that the displayed plot is identical (as close as possible) to a printed copy.

In my application the "printed copy" will never actually be printed, just loaded into a window in the second program that mirrors the window in the originating program.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Sorry for the tardy response.
My objective is to let DPlot automatically calculate the size of a plot such that it fills as much of the document window as possible( state = 0; X,Y, and WYSIWYG are ignored.)

but have DPlot adjust the font sizes used in the printed copy so that the printed copy is identical (as close as possible) to the displayed plot.
There's no way to do both. If the bitmap dimensions have a different aspect ratio than your display, then what should the bitmap font sizes be based on? The plot width or height or something else?
According to the documentation if WYSIWYG is not equal to 0...
I need to take that out of there. That setting hasn't been used for a while. With a non-zero state WYSIWYG is, in effect, turned on.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

Many thanks. Actually I'm always impressed by the promptitude of your replies.
There's no way to do both. If the bitmap dimensions have a different aspect ratio than your display, then what should the bitmap font sizes be based on? The plot width or height or something else?
Yes, I just started to realize this might be a problem as I was experimenting in a client server configuration when the client and server displays were using different pixel resolutions.
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

There's no way to do both. If the bitmap dimensions have a different aspect ratio than your display, then what should the bitmap font sizes be based on? The plot width or height or something else?
As I think more about it, the program generating the "printer" file plot knows the window height and width in the program that will be loading and displaying the plot. So the plot generating program should have enough information to select the font sizes.

So my original question is back on the table.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

It works the same regardless of output device. If the fonts look to be more or less the same proportionately on your printer without using a Size command (or Options>Extents/Intervals/Size with "Specify size" checked) that's basically just luck. But unless you have a very high resolution display I think the fonts will be smaller relative to the graph on a printout than they are on your display.

The problem is probably more obvious with your bitmaps because (just a guess) the bitmap size set with SetPluginImageDims is quite a bit smaller than the document window size in DPlot.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

The problem is, I really have no interest in the "printed" plots other than as an efficient vehicle to pass a plot file from the server, which uses DPlot Jr to generate it, to the client that will display it in a window of known pixel dimensions. The client passes the server the window size (in pixels) the plot is supposed to fit in. It can also pass any other information the server might need to generate the plot. I'm using PNG files for line plots because they are both relatively compact and can also be viewed by a variety of available software.
The problem is probably more obvious with your bitmaps because (just a guess) the bitmap size set with SetPluginImageDims is quite a bit smaller than the document window size in DPlot.
Yes, that's true. The image dimensions are on the order of 500x500. But when I view them directly, in a window, without writing to an intermediate file, in a non client/server configuration, the font sizes are completely appropriate.

Can you suggest any other mechanism using DPlot Jr to generate an appropriate compact file that, knowing the pixel dimensions of the window it must fit in, will select appropriate font sizes?
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I think about the best you can do without using a Size command is to scale the font size that you think looks good on your display by the bitmap height/document window height. So you'd do this:

Code: Select all

DPlot_Command(doc,"[FontPoints(1,?)][FontPoints(2,?)] etc. [FileSaveAs(\"Portable Network Graphics\",\".png\")]");
OR

Still pushing using the Size command: If you know the desired bitmap dimensions, divide those by 96 and that will be (on most displays) the width and height of the entire plot in inches. That will be larger than the box around the plot but depending on font sizes, whether you use axis labels and/or multiple title lines, it won't be too far off. If you multiply both by 0.85 or so it should be closer. Use the results in a Size command.

Code: Select all

double width, height;
char cmd[256];

width = 500/96 * 0.85;
height = 500/96 * 0.85;
sprintf(cmd,"[Size(1,%g,%g)]",width,height);
DPlot_Command(doc,cmd);
DPlot_Command(doc,"[FileSaveAs(\"Portable Network Graphics\",\".png\")]");
Edit: I didn't mean to suggest a printout as any sort of solution. I only meant that the scaling is the same on all devices including printers, displays, and saved bitmaps. The fonts may look right in your printed examples without using the Size command, but they're likely not the same proportional to the plot as what you see on your display. With Size, they will be - on all devices.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

Again many thanks. Your examples were a great help. My fried brain had lead me to misuse the Size() command; correct use does indeed appear to be the solution. Font choice now seems good. Any remaining issues look like they should to be solvable by minor dimension tweaking at this end (famous last words).
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

(famous last words)
I'm actually famous for my famous last words.

Let me know if you run into any trouble.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

After a few days off to deal with other crises I'm back to this one. Unfortunately I was overly optimistic. The problem has not gone away, and the dimension and pixels per inch tweaking has become a major issue. Just what I'm trying to avoid. By using the Size() function, the oversize font size problem went away. Unfortunately the bitmaps then became too small to fit the intended client window. To enlarge the bitmaps I had to reduce the specified pixels per inch value which in turn caused the font sizes to become too small to read. Because there are multiple plots involved all this is resulting in trial and error tweaking that is unacceptable for the project.

Am I correct in assuming the following? In order to select default font sizes, height, width, and many other plot parameters, DPlot must use system (including display) metrics of the computer on which it is being run. In a client-server configuration where the plot is being generated by the server, DPlot has no choice but to base its default plots on the system metrics of that server. If the client and server have different metrics, then the default plot generated by the server and passed as a file to the client will not be a good fit for the client.

What I would like to be able to do is to trick DPlot Jr on the server by sending it any necessary client system metrics etc. so it can use these for building the plot that will be displayed on the client. Passing the metrics would be no problem if there were a DPlot function to accept them to use for the plot generation. With such a function I have a feeling there would be a simple, clean solution.

Your thoughts?

-rob
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Am I correct in assuming the following? In order to select default font sizes, height, width, and many other plot parameters, DPlot must use system (including display) metrics of the computer on which it is being run. In a client-server configuration where the plot is being generated by the server, DPlot has no choice but to base its default plots on the system metrics of that server. If the client and server have different metrics, then the default plot generated by the server and passed as a file to the client will not be a good fit for the client.
That's correct except for the "default" bit - which makes it sound like a limitation. But it does that for specified font sizes if you've used the Size() command, too. Using various displays with varying resolutions should not make a difference in relative sizes. If you use Size(), then yeah font sizes will be scaled (and scaled differently on various devices), but so will the plot itself by the same scale factor. So the font size relative to the plot size should be consistent. The relative size won't be perfect because fonts are only available in discrete sizes, but if you're using TrueType fonts and not making really small bitmaps, the imperfection should not be noticeable.

When you get tired of banging your head on your desk you are certainly welcome to send me what you have.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

That's correct except for the "default" bit - which makes it sound like a limitation.
I certainly didn't mean to imply it was a limitation. Rather that DPlot does an excellent job generating an appropriate plot for the machine it's running on with little or no tweaking by the programmer. I was hoping there might be some way, possibly an undocumented function, to pass the parameters of the client machine to the server so the plot would be scaled for the former.
When you get tired of banging your head on your desk you are certainly welcome to send me what you have.
I appreciate the kind offer. However, the package includes client, server and standalone modules incorporating code scattered throughout a bunch of libraries used in different combinations depending on the module. What's worse the test data comes from a large, complex and proprietary database. that would need to be installed on your server. It would be a nightmare for both of us.

I had all this running as a demo in a standalone mode a year ago. Then I was told that to be of interest it would have to also run in a client/server mode. Someone else claims that they can do the latter easily in gnuplot. I'm trying to rescue my DPlot effort.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I still don't get it. If your goal is to make fonts appear to be the same size relative to the plot, then Size() will do that. The device resolution isn't really relevant. If you specify font sizes to be, for example, 1/20th of the plot height and use Size(), then they'll be 1/20th the plot height on all devices (other than the limitation I mentioned about discrete font sizes).

If you don't use Size then device resolution is indeed important because the plot will be drawn as large as possible and the fonts won't be scaled.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

David,

I'll try to put together a more compact and coherent spec for what I need to do and how I've tried to accomplish it. - with competing tasks it may take a day or so before it's completed.

Would you prefer we take this private or leave it public?

-rob
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

No preference - either way is fine.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

While trying to put together a more compact and coherent spec for what I need to do, how I've tried to accomplish, and the problems, I've come to the conclusion that there may be two separate problems. The first is related to FileSaveAs() slightly different than addressed in my previous thread. Let's end this thread. I'll start a new one related to the new FileSaveAs() issue.

Once that's resolved we can turn to any remaining issues.
Post Reply