1 /*
2  * SavePlotAsPdfOptions.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.studio.client.workbench.views.plots.model;
16 
17 import org.rstudio.studio.client.workbench.prefs.model.UserStateAccessor;
18 
19 public class SavePlotAsPdfOptions extends UserStateAccessor.SavePlotAsPdfOptions
20 {
SavePlotAsPdfOptions()21    protected SavePlotAsPdfOptions()
22    {
23    }
24 
createDefault()25    public static final SavePlotAsPdfOptions createDefault()
26    {
27       return SavePlotAsPdfOptions.create(8.5, 11);
28    }
29 
create(double width, double height)30    public static final SavePlotAsPdfOptions create(double width, double height)
31    {
32       return create(width, height, true, false, false);
33    }
34 
create( double width, double height, boolean portrait, boolean cairoPdf, boolean viewAfterSave)35    public static final native SavePlotAsPdfOptions create(
36                                                   double width,
37                                                   double height,
38                                                   boolean portrait,
39                                                   boolean cairoPdf,
40                                                   boolean viewAfterSave) /*-{
41       var options = new Object();
42       options.width = width;
43       options.height = height;
44       options.portrait = portrait;
45       options.cairo_pdf = cairoPdf;
46       options.viewAfterSave = viewAfterSave;
47       return options;
48    }-*/;
49 
adaptToSize( SavePlotAsPdfOptions options, double width, double height)50    public static final SavePlotAsPdfOptions adaptToSize(
51                                             SavePlotAsPdfOptions options,
52                                             double width,
53                                             double height)
54    {
55       return SavePlotAsPdfOptions.create(width,
56                                          height,
57                                          options.getPortrait(),
58                                          options.getCairoPdf(),
59                                          options.getViewAfterSave());
60    }
61 
areEqual(SavePlotAsPdfOptions a, SavePlotAsPdfOptions b)62    public static native boolean areEqual(SavePlotAsPdfOptions a, SavePlotAsPdfOptions b) /*-{
63       if (a === null ^ b === null)
64          return false;
65       if (a === null)
66          return true;
67       return a.width === b.width &&
68              a.height === b.height &&
69              a.portrait === b.portrait &&
70              a.cairo_pdf === b.cairo_pdf &&
71              a.viewAfterSave === b.viewAfterSave;
72    }-*/;
73 }
74