bugGNU Octave - Bugs: bug #59355, Font size scaled when -F and -S...

 
 

bug #59355: Font size scaled when -F and -S option are used together

Submitter:  Miloš Petrašinović <mpetrasinovic>
Submitted:  Mon 26 Oct 2020 04:39:34 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Confirmed Assigned to:  None
Originator Name:  Miloš Petrašinović Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 02 Nov 2020 10:43:39 PM UTC, comment #5: 

I think this may be an issue of interpretation about what is the desired result.  The code in print.m that handles the -F options is


        if (! isempty (opts.fontsize))
          ## Changing all fontsizes to a fixed value
          if (ischar (opts.fontsize))
            fontsize = str2double (opts.fontsize);
          else
            fontsize = opts.fontsize;
          endif
          if (do_scalefontsize)
            ## This is done to work around the bbox being whole numbers.
            fontsize *= opts.scalefontsize;
          endif


Instead of assigning the fontsize as given by the -F option, it applies a scaled version so that if you change the sizing with -S option things don't look weird.

As an example, try


print('fig2.svg','-dsvg',['-S' num2str(pos(3)/4) ',' num2str(pos(4))],'-F:18');


This uses 1/4 of the x-dimension and produces a narrow, but tall, plot which is attached as fig2.orig.svg.  Note that the plot labels have been scaled so that the plot still looks reasonable.

I disabled font scaling and then made the same squished plot.  It is attached as fig2.new.svg.  I prefer the look of existing code.


(file #50197, file #50198)

Rik <rik5>
Group administrator
Mon 02 Nov 2020 09:51:09 PM UTC, comment #4: 

Sample test code for bug:


pos = [300 200 560 420];
figure(1,'paperunits','points', 'paperposition', [0,0,pos(3:4)])
plot([0,1],[0,1]);
set(gca,'fontunits','points','fontsize',18,'FontName','Arial');
print('fig2.svg','-dsvg',['-S' num2str(pos(3)) ',' num2str(pos(4))],'-F:18');


This is also attached as tst_svg_fontsz.m

(file #50196)

Rik <rik5>
Group administrator
Mon 02 Nov 2020 08:22:03 PM UTC, comment #3: 

For completeness, I can this test


pos = [300 200 560 420];
figure(1,'paperunits','points', 'paperposition', [0,0,pos(3:4)])
plot([0,1],[0,1]);
set(gca,'fontunits','points','fontsize',18,'FontName','Arial');
print('fig1.svg','-dsvg', '-F:14');


This results in an SVG file where the font is 14 points.  Hence, there is only once combination of options that is incorrect.

Rik <rik5>
Group administrator
Sat 31 Oct 2020 04:48:33 PM UTC, comment #2: 

Thank you for all clarifications about this mechanism. I would like to see somewhere in documentation this simple explanation (or some wiki page).

Your last sentence is the reason I wrote this way title for this bug report. For fig2.svg I get 20.5889pt font size, after running following script:


pos = [300 200 560 420];
figure(1,'paperunits','points','papersize',pos(3:4),...
  'paperposition', [0,0,pos(3:4)])
plot([0,1],[0,1]);
set(gca,'fontunits','points','fontsize',18,'FontName','Arial');
print('fig1.svg','-dsvg');
print('fig1.png','-dpng');
print('fig2.svg','-dsvg',['-S' num2str(pos(3)) ',' num2str(pos(4))],'-F:18');
print('fig2.png','-dpng',['-S' num2str(pos(3)) ',' num2str(pos(4))],'-F:18');


Miloš Petrašinović <mpetrasinovic>
Fri 30 Oct 2020 09:24:41 PM UTC, comment #1: 

I think most of this is actually correct.

First, the "papersize" property is only used for printing to page-like formats (PostScript, PDF).  Try 'help print' to see all of the options and caveats for printing.  For all other formats, the size is taken from the "paperposition" property.  Hence, the creation of the figure needs to be


figure(1,'paperunits','points', 'paperposition', [0,0,pos(3:4)])


If I run the rest of the test script after making the modification above I find that fig1.svg is indeed 560x420 as measured in points.  The fontsize is 18.

The size of fig1.png is 1166x875 pixels.  This also makes sense.  There are 72 points/inch so 560 points is 7.7778 inches.  The resolution for bitmapped formats, like png, is 150 dpi/inch so multiplying 7.7778 by 150 = 1166.  See the "-r" resolution option for print to change this default.

The "-S" option overrides the default mechanism above.  For fig2.png, the result is 560x420 pixels and for fig2.svg the result is 560x420 points.

The one thing I don't quite understand is that for fig2.svg the size of the font is 17.496 points instead of 18.0 points.  If there is a problem, it is with this one part of the svg file.


Rik <rik5>
Group administrator
Mon 26 Oct 2020 04:39:34 PM UTC, original submission:  

After running the following script for fig1.svg I get 494x370 pt and for fig2.svg I get 560x420 pt while for fig1.png I get 1029x772 px and for fig2.png I get 560x420px. I can see that there is a difference in displayed font size (in figure window) and in saved images, also in fig2.svg font size is not 18pt. Are those expected results?


pos = [300 200 560 420];
figure(1,'paperunits','points','papersize',pos(3:4))
plot([0,1],[0,1]);
set(gca,'fontunits','points','fontsize',18,'FontName','Arial');
print('fig1.svg','-dsvg');
print('fig1.png','-dpng');
print('fig2.svg','-dsvg',['-S' num2str(pos(3)) ',' num2str(pos(4))],'-F:18');
print('fig2.png','-dpng',['-S' num2str(pos(3)) ',' num2str(pos(4))],'-F:18');

get(get(f,'Parent'),'screenpixelsperinch') % ans = 81.597


Miloš Petrašinović <mpetrasinovic>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #50197:  fig2.orig.svg added by rik5 (8KiB - image/svg+xml)
file #50198:  fig2.new.svg added by rik5 (8KiB - image/svg+xml)
file #50196:  tst_svg_fontsz.m added by rik5 (477B - text/x-matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mpetrasinovic (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-11-02 rik5 Attached File- Added fig2.orig.svg, #50197
        Attached File- Added fig2.new.svg, #50198
        SummaryIncorect font size in printed svg when -S and -F option are used together Font size scaled when -F and -S option are used together
    2020-11-02 rik5 Attached File- Added tst_svg_fontsz.m, #50196
        StatusNone Confirmed
        SummaryIncorect font size in printed svg Incorect font size in printed svg when -S and -F option are used together
    2020-10-31 rik5 Release6.0.92 dev
    2020-10-30 rik5 Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-aa77.
    Corresponding source code