2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2006-04-21 15:09:32 +00:00
|
|
|
|
* gtkpapersize.c: Paper Size
|
|
|
|
|
* Copyright (C) 2006, Red Hat, Inc.
|
2007-05-01 22:26:00 +00:00
|
|
|
|
* Copyright © 2006, 2007 Christian Persch
|
2006-04-21 15:09:32 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-21 15:09:32 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#if defined(HAVE__NL_PAPER_HEIGHT) && defined(HAVE__NL_PAPER_WIDTH)
|
|
|
|
|
#include <langinfo.h>
|
|
|
|
|
#endif
|
2015-03-22 19:15:42 +00:00
|
|
|
|
#include <math.h>
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkpapersize.h"
|
2006-04-23 05:48:04 +00:00
|
|
|
|
#include "gtkprintutils.h"
|
2007-04-29 06:23:58 +00:00
|
|
|
|
#include "gtkprintoperation.h" /* for GtkPrintError */
|
2022-09-24 13:07:56 +00:00
|
|
|
|
#include <glib/gi18n-lib.h>
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2013-11-20 17:33:03 +00:00
|
|
|
|
/* _gtk_load_custom_papers() only on Unix so far */
|
|
|
|
|
#ifdef G_OS_UNIX
|
2012-10-02 17:27:25 +00:00
|
|
|
|
#include "gtkcustompaperunixdialog.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
#include "paper_names_offsets.c"
|
|
|
|
|
|
2010-09-27 01:49:49 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* GtkPaperSize:
|
2010-09-27 01:49:49 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* `GtkPaperSize` handles paper sizes.
|
|
|
|
|
*
|
|
|
|
|
* It uses the standard called
|
2014-02-04 23:53:51 +00:00
|
|
|
|
* [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html)
|
2010-09-27 01:49:49 +00:00
|
|
|
|
* to name the paper sizes (and to get the data for the page sizes).
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* In addition to standard paper sizes, `GtkPaperSize` allows to
|
2010-09-27 01:49:49 +00:00
|
|
|
|
* construct custom paper sizes with arbitrary dimensions.
|
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* The `GtkPaperSize` object stores not only the dimensions (width
|
2010-09-27 01:49:49 +00:00
|
|
|
|
* and height) of a paper size and its name, it also provides
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* default print margins.
|
2010-09-27 01:49:49 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
struct _GtkPaperSize
|
|
|
|
|
{
|
|
|
|
|
const PaperInfo *info;
|
|
|
|
|
|
|
|
|
|
/* If these are not set we fall back to info */
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *name;
|
|
|
|
|
char *display_name;
|
|
|
|
|
char *ppd_name;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width, height; /* Stored in mm */
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gboolean is_custom;
|
2014-10-06 10:37:56 +00:00
|
|
|
|
gboolean is_ipp;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-04-27 11:31:23 +00:00
|
|
|
|
G_DEFINE_BOXED_TYPE (GtkPaperSize, gtk_paper_size,
|
|
|
|
|
gtk_paper_size_copy,
|
|
|
|
|
gtk_paper_size_free)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
static const PaperInfo *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
lookup_paper_info (const char *name)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
int lower = 0;
|
|
|
|
|
int upper = G_N_ELEMENTS (standard_names_offsets) - 1;
|
|
|
|
|
int mid;
|
|
|
|
|
int cmp;
|
|
|
|
|
|
2011-01-13 03:30:08 +00:00
|
|
|
|
do
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
mid = (lower + upper) / 2;
|
|
|
|
|
cmp = strcmp (name, paper_names + standard_names_offsets[mid].name);
|
|
|
|
|
if (cmp < 0)
|
|
|
|
|
upper = mid - 1;
|
|
|
|
|
else if (cmp > 0)
|
|
|
|
|
lower = mid + 1;
|
|
|
|
|
else
|
2011-01-13 03:30:08 +00:00
|
|
|
|
return &standard_names_offsets[mid];
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
while (lower <= upper);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-24 18:40:36 +00:00
|
|
|
|
parse_media_size (const char *size,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double *width_mm,
|
|
|
|
|
double *height_mm)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
char *e;
|
|
|
|
|
double short_dim, long_dim;
|
|
|
|
|
|
|
|
|
|
p = size;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
short_dim = g_ascii_strtod (p, &e);
|
|
|
|
|
|
|
|
|
|
if (p == e || *e != 'x')
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
p = e + 1; /* Skip x */
|
|
|
|
|
|
|
|
|
|
long_dim = g_ascii_strtod (p, &e);
|
|
|
|
|
|
|
|
|
|
if (p == e)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
p = e;
|
|
|
|
|
|
|
|
|
|
if (strcmp (p, "in") == 0)
|
|
|
|
|
{
|
|
|
|
|
short_dim = short_dim * MM_PER_INCH;
|
|
|
|
|
long_dim = long_dim * MM_PER_INCH;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp (p, "mm") != 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (width_mm)
|
|
|
|
|
*width_mm = short_dim;
|
|
|
|
|
if (height_mm)
|
|
|
|
|
*height_mm = long_dim;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-24 18:40:36 +00:00
|
|
|
|
parse_full_media_size_name (const char *full_name,
|
|
|
|
|
char **name,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double *width_mm,
|
|
|
|
|
double *height_mm)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
const char *end_of_name;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
/* From the spec:
|
|
|
|
|
media-size-self-describing-name =
|
|
|
|
|
( class-in "_" size-name "_" short-dim "x" long-dim "in" ) |
|
|
|
|
|
( class-mm "_" size-name "_" short-dim "x" long-dim "mm" )
|
|
|
|
|
class-in = "custom" | "na" | "asme" | "roc" | "oe"
|
|
|
|
|
class-mm = "custom" | "iso" | "jis" | "jpn" | "prc" | "om"
|
|
|
|
|
size-name = ( lowalpha | digit ) *( lowalpha | digit | "-" )
|
|
|
|
|
short-dim = dim
|
|
|
|
|
long-dim = dim
|
|
|
|
|
dim = integer-part [fraction-part] | "0" fraction-part
|
|
|
|
|
integer-part = non-zero-digit *digit
|
|
|
|
|
fraction-part = "." *digit non-zero-digit
|
|
|
|
|
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
|
|
|
|
|
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
|
|
|
|
|
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
|
|
|
|
|
non-zero-digit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
|
|
|
|
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
p = strchr (full_name, '_');
|
|
|
|
|
if (p == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
p++; /* Skip _ */
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
p = strchr (p, '_');
|
|
|
|
|
if (p == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
end_of_name = p;
|
|
|
|
|
|
|
|
|
|
p++; /* Skip _ */
|
|
|
|
|
|
|
|
|
|
if (!parse_media_size (p, width_mm, height_mm))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
|
*name = g_strndup (full_name, end_of_name - full_name);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkPaperSize *
|
|
|
|
|
gtk_paper_size_new_from_info (const PaperInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2007-05-01 22:26:00 +00:00
|
|
|
|
size = g_slice_new0 (GtkPaperSize);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
size->info = info;
|
|
|
|
|
size->width = info->width;
|
|
|
|
|
size->height = info->height;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new:
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @name: (nullable): a paper size name
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Creates a new `GtkPaperSize` object by parsing a
|
2014-02-04 23:53:51 +00:00
|
|
|
|
* [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf)
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* paper name.
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*
|
|
|
|
|
* If @name is %NULL, the default paper size is returned,
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* see [func@Gtk.PaperSize.get_default].
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* to free it
|
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPaperSize *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_paper_size_new (const char *name)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
char *short_name;
|
|
|
|
|
double width, height;
|
2006-04-23 06:26:10 +00:00
|
|
|
|
const PaperInfo *info;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = gtk_paper_size_get_default ();
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (parse_full_media_size_name (name, &short_name, &width, &height))
|
|
|
|
|
{
|
2011-01-13 03:30:08 +00:00
|
|
|
|
info = lookup_paper_info (short_name);
|
|
|
|
|
if (info != NULL && info->width == width && info->height == height)
|
|
|
|
|
{
|
|
|
|
|
size = gtk_paper_size_new_from_info (info);
|
|
|
|
|
g_free (short_name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
size = g_slice_new0 (GtkPaperSize);
|
|
|
|
|
|
|
|
|
|
size->width = width;
|
|
|
|
|
size->height = height;
|
|
|
|
|
size->name = short_name;
|
|
|
|
|
size->display_name = g_strdup (short_name);
|
|
|
|
|
if (strncmp (short_name, "custom", 6) == 0)
|
|
|
|
|
size->is_custom = TRUE;
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
info = lookup_paper_info (name);
|
|
|
|
|
if (info != NULL)
|
2011-01-13 03:30:08 +00:00
|
|
|
|
size = gtk_paper_size_new_from_info (info);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
else
|
2011-01-13 03:30:08 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Unknown paper size %s", name);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
size = g_slice_new0 (GtkPaperSize);
|
|
|
|
|
size->name = g_strdup (name);
|
|
|
|
|
size->display_name = g_strdup (name);
|
|
|
|
|
/* Default to A4 size */
|
|
|
|
|
size->width = 210;
|
|
|
|
|
size->height = 297;
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
|
|
|
|
improve_displayname (const char *name)
|
2014-09-30 04:55:03 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *p, *p1, *p2, *s;
|
2014-09-30 04:55:03 +00:00
|
|
|
|
|
|
|
|
|
p = strrchr (name, 'x');
|
|
|
|
|
if (p && p != name &&
|
|
|
|
|
g_ascii_isdigit (*(p - 1)) &&
|
|
|
|
|
g_ascii_isdigit (*(p + 1)))
|
|
|
|
|
{
|
|
|
|
|
p1 = g_strndup (name, p - name);
|
|
|
|
|
p2 = g_strdup (p + 1);
|
|
|
|
|
s = g_strconcat (p1, "×", p2, NULL);
|
|
|
|
|
g_free (p1);
|
|
|
|
|
g_free (p2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
s = g_strdup (name);
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new_from_ppd:
|
|
|
|
|
* @ppd_name: a PPD paper name
|
|
|
|
|
* @ppd_display_name: the corresponding human-readable name
|
|
|
|
|
* @width: the paper width, in points
|
|
|
|
|
* @height: the paper height in points
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Creates a new `GtkPaperSize` object by using
|
2011-01-13 03:30:08 +00:00
|
|
|
|
* PPD information.
|
|
|
|
|
*
|
|
|
|
|
* If @ppd_name is not a recognized PPD paper name,
|
|
|
|
|
* @ppd_display_name, @width and @height are used to
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* construct a custom `GtkPaperSize` object.
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* to free it
|
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPaperSize *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_paper_size_new_from_ppd (const char *ppd_name,
|
|
|
|
|
const char *ppd_display_name,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width,
|
|
|
|
|
double height)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
const char *lookup_ppd_name;
|
|
|
|
|
char *freeme;
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
int i;
|
2014-09-30 04:55:03 +00:00
|
|
|
|
char *display_name;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
lookup_ppd_name = ppd_name;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
freeme = NULL;
|
|
|
|
|
/* Strip out Traverse suffix in matching. */
|
|
|
|
|
if (g_str_has_suffix (ppd_name, ".Transverse"))
|
|
|
|
|
{
|
|
|
|
|
lookup_ppd_name = freeme =
|
2011-01-13 03:30:08 +00:00
|
|
|
|
g_strndup (ppd_name, strlen (ppd_name) - strlen (".Transverse"));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2014-09-30 04:55:03 +00:00
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (standard_names_offsets); i++)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (standard_names_offsets[i].ppd_name != -1 &&
|
2011-01-13 03:30:08 +00:00
|
|
|
|
strcmp (paper_names + standard_names_offsets[i].ppd_name, lookup_ppd_name) == 0)
|
|
|
|
|
{
|
|
|
|
|
size = gtk_paper_size_new_from_info (&standard_names_offsets[i]);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2014-09-30 04:55:03 +00:00
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (extra_ppd_names_offsets); i++)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (strcmp (paper_names + extra_ppd_names_offsets[i].ppd_name, lookup_ppd_name) == 0)
|
2011-01-13 03:30:08 +00:00
|
|
|
|
{
|
|
|
|
|
size = gtk_paper_size_new (paper_names + extra_ppd_names_offsets[i].standard_name);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
name = g_strconcat ("ppd_", ppd_name, NULL);
|
2014-09-30 04:55:03 +00:00
|
|
|
|
display_name = improve_displayname (ppd_display_name);
|
|
|
|
|
size = gtk_paper_size_new_custom (name, display_name, width, height, GTK_UNIT_POINTS);
|
|
|
|
|
g_free (display_name);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
|
|
if (size->info == NULL ||
|
|
|
|
|
size->info->ppd_name == -1 ||
|
|
|
|
|
strcmp (paper_names + size->info->ppd_name, ppd_name) != 0)
|
|
|
|
|
size->ppd_name = g_strdup (ppd_name);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_free (freeme);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 10:37:56 +00:00
|
|
|
|
/* Tolerance of paper size in points according to PostScript Language Reference */
|
|
|
|
|
#define PAPER_SIZE_TOLERANCE 5
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new_from_ipp:
|
2014-10-22 04:03:52 +00:00
|
|
|
|
* @ipp_name: an IPP paper name
|
2014-10-06 10:37:56 +00:00
|
|
|
|
* @width: the paper width, in points
|
|
|
|
|
* @height: the paper height in points
|
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Creates a new `GtkPaperSize` object by using
|
2014-10-06 10:37:56 +00:00
|
|
|
|
* IPP information.
|
|
|
|
|
*
|
|
|
|
|
* If @ipp_name is not a recognized paper name,
|
|
|
|
|
* @width and @height are used to
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* construct a custom `GtkPaperSize` object.
|
2014-10-06 10:37:56 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
|
2014-10-06 10:37:56 +00:00
|
|
|
|
* to free it
|
|
|
|
|
*/
|
|
|
|
|
GtkPaperSize *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_paper_size_new_from_ipp (const char *ipp_name,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width,
|
|
|
|
|
double height)
|
2014-10-06 10:37:56 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name = NULL;
|
2014-10-06 10:37:56 +00:00
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
float x_dimension;
|
|
|
|
|
float y_dimension;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *display_name = NULL;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2014-10-06 10:37:56 +00:00
|
|
|
|
|
|
|
|
|
/* Find paper size according to its name */
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (standard_names_offsets); i++)
|
|
|
|
|
{
|
|
|
|
|
if (standard_names_offsets[i].name != -1)
|
|
|
|
|
name = paper_names + standard_names_offsets[i].name;
|
|
|
|
|
if (name != NULL &&
|
|
|
|
|
/* Given paper size name is equal to a name
|
|
|
|
|
from the standard paper size names list. */
|
|
|
|
|
((g_strcmp0 (ipp_name, name) == 0) ||
|
|
|
|
|
/* Given paper size name is prefixed by a name
|
|
|
|
|
from the standard paper size names list +
|
|
|
|
|
it consists of size in its name (e.g. iso_a4_210x297mm). */
|
|
|
|
|
(g_str_has_prefix (ipp_name, name) &&
|
|
|
|
|
strlen (ipp_name) > strlen (name) + 2 &&
|
|
|
|
|
ipp_name[strlen (ipp_name)] == '_' &&
|
|
|
|
|
g_ascii_isdigit (ipp_name[strlen (ipp_name) + 1]) &&
|
|
|
|
|
(g_str_has_suffix (ipp_name, "mm") ||
|
|
|
|
|
g_str_has_suffix (ipp_name, "in")))))
|
|
|
|
|
{
|
|
|
|
|
display_name = g_strdup (g_dpgettext2 (GETTEXT_PACKAGE,
|
|
|
|
|
"paper size",
|
|
|
|
|
paper_names + standard_names_offsets[i].display_name));
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find paper size according to its size */
|
|
|
|
|
if (display_name == NULL)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (standard_names_offsets); i++)
|
|
|
|
|
{
|
|
|
|
|
x_dimension = _gtk_print_convert_from_mm (standard_names_offsets[i].width, GTK_UNIT_POINTS);
|
|
|
|
|
y_dimension = _gtk_print_convert_from_mm (standard_names_offsets[i].height, GTK_UNIT_POINTS);
|
|
|
|
|
|
2015-03-22 19:15:42 +00:00
|
|
|
|
if (fabs (x_dimension - width) <= PAPER_SIZE_TOLERANCE &&
|
|
|
|
|
fabs (y_dimension - height) <= PAPER_SIZE_TOLERANCE)
|
2014-10-06 10:37:56 +00:00
|
|
|
|
{
|
|
|
|
|
display_name = g_strdup (g_dpgettext2 (GETTEXT_PACKAGE,
|
|
|
|
|
"paper size",
|
|
|
|
|
paper_names + standard_names_offsets[i].display_name));
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fallback to name of the paper size as given in "ipp_name" parameter */
|
|
|
|
|
if (display_name == NULL)
|
|
|
|
|
display_name = g_strdup (ipp_name);
|
|
|
|
|
|
|
|
|
|
size = gtk_paper_size_new_custom (ipp_name, display_name, width, height, GTK_UNIT_POINTS);
|
|
|
|
|
size->is_custom = !found;
|
|
|
|
|
size->is_ipp = found;
|
|
|
|
|
|
|
|
|
|
g_free (display_name);
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new_custom:
|
2011-01-13 03:30:08 +00:00
|
|
|
|
* @name: the paper name
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* @display_name: the human-readable name
|
|
|
|
|
* @width: the paper width, in units of @unit
|
|
|
|
|
* @height: the paper height, in units of @unit
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for @width and @height. not %GTK_UNIT_NONE.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Creates a new `GtkPaperSize` object with the
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* given parameters.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: a new `GtkPaperSize` object, use [method@Gtk.PaperSize.free]
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* to free it
|
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPaperSize *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_paper_size_new_custom (const char *name,
|
|
|
|
|
const char *display_name,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width,
|
|
|
|
|
double height,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2012-02-20 13:24:33 +00:00
|
|
|
|
g_return_val_if_fail (unit != GTK_UNIT_NONE, NULL);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2007-05-01 22:26:00 +00:00
|
|
|
|
size = g_slice_new0 (GtkPaperSize);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
size->name = g_strdup (name);
|
|
|
|
|
size->display_name = g_strdup (display_name);
|
|
|
|
|
size->is_custom = TRUE;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
size->width = _gtk_print_convert_to_mm (width, unit);
|
|
|
|
|
size->height = _gtk_print_convert_to_mm (height, unit);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_copy:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @other: a `GtkPaperSize`
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Copies an existing `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a copy of @other
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
GtkPaperSize *
|
|
|
|
|
gtk_paper_size_copy (GtkPaperSize *other)
|
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
|
2007-05-01 22:26:00 +00:00
|
|
|
|
size = g_slice_new0 (GtkPaperSize);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
size->info = other->info;
|
|
|
|
|
if (other->name)
|
|
|
|
|
size->name = g_strdup (other->name);
|
|
|
|
|
if (other->display_name)
|
|
|
|
|
size->display_name = g_strdup (other->display_name);
|
|
|
|
|
if (other->ppd_name)
|
|
|
|
|
size->ppd_name = g_strdup (other->ppd_name);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
size->width = other->width;
|
|
|
|
|
size->height = other->height;
|
|
|
|
|
size->is_custom = other->is_custom;
|
2014-10-06 10:37:56 +00:00
|
|
|
|
size->is_ipp = other->is_ipp;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_free:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize`
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Free the given `GtkPaperSize` object.
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_paper_size_free (GtkPaperSize *size)
|
|
|
|
|
{
|
|
|
|
|
g_free (size->name);
|
|
|
|
|
g_free (size->display_name);
|
|
|
|
|
g_free (size->ppd_name);
|
2007-05-01 22:26:00 +00:00
|
|
|
|
|
|
|
|
|
g_slice_free (GtkPaperSize, size);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_is_equal:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size1: a `GtkPaperSize` object
|
|
|
|
|
* @size2: another `GtkPaperSize` object
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Compares two `GtkPaperSize` objects.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE, if @size1 and @size2
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* represent the same paper size
|
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_paper_size_is_equal (GtkPaperSize *size1,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
GtkPaperSize *size2)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (size1->info != NULL && size2->info != NULL)
|
|
|
|
|
return size1->info == size2->info;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
return strcmp (gtk_paper_size_get_name (size1),
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_name (size2)) == 0;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2006-04-23 06:26:10 +00:00
|
|
|
|
|
2007-04-29 04:50:28 +00:00
|
|
|
|
/**
|
2007-04-30 06:03:01 +00:00
|
|
|
|
* gtk_paper_size_get_paper_sizes:
|
|
|
|
|
* @include_custom: whether to include custom paper sizes
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* as defined in the page setup dialog
|
2007-04-29 04:50:28 +00:00
|
|
|
|
*
|
2007-04-30 06:03:01 +00:00
|
|
|
|
* Creates a list of known paper sizes.
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (element-type GtkPaperSize) (transfer full): a newly allocated list of newly
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* allocated `GtkPaperSize` objects
|
2007-04-29 04:50:28 +00:00
|
|
|
|
*/
|
|
|
|
|
GList *
|
2007-04-30 06:03:01 +00:00
|
|
|
|
gtk_paper_size_get_paper_sizes (gboolean include_custom)
|
2007-04-29 04:50:28 +00:00
|
|
|
|
{
|
|
|
|
|
GList *list = NULL;
|
|
|
|
|
guint i;
|
2013-11-20 17:33:03 +00:00
|
|
|
|
/* _gtk_load_custom_papers() only on Unix so far */
|
|
|
|
|
#ifdef G_OS_UNIX
|
2007-05-01 22:31:29 +00:00
|
|
|
|
if (include_custom)
|
|
|
|
|
{
|
|
|
|
|
GList *page_setups, *l;
|
|
|
|
|
|
|
|
|
|
page_setups = _gtk_load_custom_papers ();
|
|
|
|
|
for (l = page_setups; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkPageSetup *setup = (GtkPageSetup *) l->data;
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
|
|
|
|
|
size = gtk_page_setup_get_paper_size (setup);
|
|
|
|
|
list = g_list_prepend (list, gtk_paper_size_copy (size));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-02 03:20:59 +00:00
|
|
|
|
g_list_free_full (page_setups, g_object_unref);
|
2007-05-01 22:31:29 +00:00
|
|
|
|
}
|
2007-04-30 07:42:12 +00:00
|
|
|
|
#endif
|
2007-04-29 04:50:28 +00:00
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (standard_names_offsets); ++i)
|
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *size;
|
|
|
|
|
|
|
|
|
|
size = gtk_paper_size_new_from_info (&standard_names_offsets[i]);
|
|
|
|
|
list = g_list_prepend (list, size);
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 06:03:01 +00:00
|
|
|
|
return g_list_reverse (list);
|
2007-04-29 04:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 06:03:01 +00:00
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_name:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the name of the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the name of @size
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_paper_size_get_name (GtkPaperSize *size)
|
|
|
|
|
{
|
|
|
|
|
if (size->name)
|
|
|
|
|
return size->name;
|
|
|
|
|
g_assert (size->info != NULL);
|
|
|
|
|
return paper_names + size->info->name;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_display_name:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the human-readable name of the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the human-readable name of @size
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_paper_size_get_display_name (GtkPaperSize *size)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *display_name;
|
2006-04-25 03:44:57 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (size->display_name)
|
|
|
|
|
return size->display_name;
|
2006-04-25 03:44:57 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
g_assert (size->info != NULL);
|
2006-04-25 03:44:57 +00:00
|
|
|
|
|
|
|
|
|
display_name = paper_names + size->info->display_name;
|
2008-10-27 03:07:16 +00:00
|
|
|
|
return g_dpgettext2 (GETTEXT_PACKAGE, "paper size", display_name);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_ppd_name:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the PPD name of the `GtkPaperSize`, which
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* may be %NULL.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the PPD name of @size
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_paper_size_get_ppd_name (GtkPaperSize *size)
|
|
|
|
|
{
|
|
|
|
|
if (size->ppd_name)
|
|
|
|
|
return size->ppd_name;
|
|
|
|
|
if (size->info)
|
|
|
|
|
return paper_names + size->info->ppd_name;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_width:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the paper width of the `GtkPaperSize`, in
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* units of @unit.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the paper width
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_width (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
|
return _gtk_print_convert_from_mm (size->width, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
2006-04-23 06:26:10 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_height:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the paper height of the `GtkPaperSize`, in
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* units of @unit.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the paper height
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_height (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2006-04-23 05:48:04 +00:00
|
|
|
|
return _gtk_print_convert_from_mm (size->height, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_is_custom:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* Returns %TRUE if @size is not a standard paper size.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: whether @size is a custom paper size.
|
2006-04-23 06:26:10 +00:00
|
|
|
|
**/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_paper_size_is_custom (GtkPaperSize *size)
|
|
|
|
|
{
|
|
|
|
|
return size->is_custom;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 10:37:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_is_ipp:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2014-10-06 10:37:56 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns %TRUE if @size is an IPP standard paper size.
|
|
|
|
|
*
|
|
|
|
|
* Returns: whether @size is not an IPP custom paper size.
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_paper_size_is_ipp (GtkPaperSize *size)
|
|
|
|
|
{
|
|
|
|
|
return size->is_ipp;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_set_size:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a custom `GtkPaperSize` object
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* @width: the new width in units of @unit
|
|
|
|
|
* @height: the new height in units of @unit
|
|
|
|
|
* @unit: the unit for @width and @height
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2006-04-23 06:26:10 +00:00
|
|
|
|
* Changes the dimensions of a @size to @width x @height.
|
|
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
|
void
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_set_size (GtkPaperSize *size,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width,
|
|
|
|
|
double height,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (size != NULL);
|
|
|
|
|
g_return_if_fail (size->is_custom);
|
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
size->width = _gtk_print_convert_to_mm (width, unit);
|
|
|
|
|
size->height = _gtk_print_convert_to_mm (height, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define NL_PAPER_GET(x) \
|
|
|
|
|
((union { char *string; unsigned int word; })nl_langinfo(x)).word
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_default:
|
|
|
|
|
*
|
2011-01-13 03:30:08 +00:00
|
|
|
|
* Returns the name of the default paper size, which
|
|
|
|
|
* depends on the current locale.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the name of the default paper size. The string
|
2019-02-05 10:26:20 +00:00
|
|
|
|
* is owned by GTK and should not be modified.
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *
|
2006-04-21 15:09:32 +00:00
|
|
|
|
gtk_paper_size_get_default (void)
|
|
|
|
|
{
|
|
|
|
|
char *locale, *freeme = NULL;
|
|
|
|
|
const char *paper_size;
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE__NL_PAPER_HEIGHT) && defined(HAVE__NL_PAPER_WIDTH)
|
|
|
|
|
{
|
|
|
|
|
int width = NL_PAPER_GET (_NL_PAPER_WIDTH);
|
|
|
|
|
int height = NL_PAPER_GET (_NL_PAPER_HEIGHT);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (width == 210 && height == 297)
|
|
|
|
|
return GTK_PAPER_NAME_A4;
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
if (width == 216 && height == 279)
|
|
|
|
|
return GTK_PAPER_NAME_LETTER;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
freeme = locale = g_win32_getlocale ();
|
|
|
|
|
#elif defined(LC_PAPER)
|
|
|
|
|
locale = setlocale(LC_PAPER, NULL);
|
|
|
|
|
#else
|
|
|
|
|
locale = setlocale(LC_MESSAGES, NULL);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (!locale)
|
|
|
|
|
return GTK_PAPER_NAME_A4;
|
|
|
|
|
|
2010-05-11 14:38:07 +00:00
|
|
|
|
/* CLDR 1.8.1
|
|
|
|
|
* http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/territory_language_information.html
|
|
|
|
|
*/
|
|
|
|
|
if (g_regex_match_simple("[^_.@]{2,3}_(BZ|CA|CL|CO|CR|GT|MX|NI|PA|PH|PR|SV|US|VE)",
|
|
|
|
|
locale, G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED))
|
2006-04-21 15:09:32 +00:00
|
|
|
|
paper_size = GTK_PAPER_NAME_LETTER;
|
|
|
|
|
else
|
|
|
|
|
paper_size = GTK_PAPER_NAME_A4;
|
|
|
|
|
|
|
|
|
|
g_free (freeme);
|
|
|
|
|
return paper_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* These get the default margins used for the paper size. Its
|
|
|
|
|
* larger than most printers margins, so that it will be within
|
|
|
|
|
* the imageble area on any printer.
|
|
|
|
|
*
|
2014-02-07 18:38:26 +00:00
|
|
|
|
* I’ve taken the actual values used from the OSX page setup dialog.
|
2014-02-07 18:42:09 +00:00
|
|
|
|
* I’m not sure exactly where they got these values for, but might
|
2006-04-21 15:09:32 +00:00
|
|
|
|
* correspond to this (from ghostscript docs):
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2006-04-21 15:09:32 +00:00
|
|
|
|
* All DeskJets have 0.5 inches (1.27cm) of unprintable bottom margin,
|
|
|
|
|
* due to the mechanical arrangement used to grab the paper. Side margins
|
|
|
|
|
* are approximately 0.25 inches (0.64cm) for U.S. letter paper, and 0.15
|
|
|
|
|
* inches (0.38cm) for A4.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_default_top_margin:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the default top margin for the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the default top margin
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_default_top_margin (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double margin;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
|
|
|
|
|
return _gtk_print_convert_from_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_default_bottom_margin:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the default bottom margin for the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the default bottom margin
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_default_bottom_margin (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double margin;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
|
|
name = gtk_paper_size_get_name (size);
|
|
|
|
|
if (strcmp (name, "na_letter") == 0 ||
|
|
|
|
|
strcmp (name, "na_legal") == 0 ||
|
|
|
|
|
strcmp (name, "iso_a4") == 0)
|
2006-04-23 05:48:04 +00:00
|
|
|
|
margin = _gtk_print_convert_to_mm (0.56, GTK_UNIT_INCH);
|
2011-01-13 03:30:08 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
return _gtk_print_convert_from_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_default_left_margin:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the default left margin for the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the default left margin
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_default_left_margin (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double margin;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
|
|
|
|
|
return _gtk_print_convert_from_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 06:26:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_get_default_right_margin:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize` object
|
2012-02-20 13:24:33 +00:00
|
|
|
|
* @unit: the unit for the return value, not %GTK_UNIT_NONE
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Gets the default right margin for the `GtkPaperSize`.
|
2011-01-13 03:30:08 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the default right margin
|
2006-04-23 06:26:10 +00:00
|
|
|
|
*/
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double
|
2011-01-13 03:30:08 +00:00
|
|
|
|
gtk_paper_size_get_default_right_margin (GtkPaperSize *size,
|
|
|
|
|
GtkUnit unit)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double margin;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
2006-04-23 05:48:04 +00:00
|
|
|
|
margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
|
|
|
|
|
return _gtk_print_convert_from_mm (margin, unit);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-29 06:23:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new_from_key_file:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @key_file: the `GKeyFile` to retrieve the papersize from
|
2018-11-18 12:36:50 +00:00
|
|
|
|
* @group_name: (nullable): the name of the group in the key file to read,
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* or %NULL to read the first group
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @error: (nullable): return location for an error
|
2007-04-29 06:23:58 +00:00
|
|
|
|
*
|
|
|
|
|
* Reads a paper size from the group @group_name in the key file
|
2011-01-13 03:30:08 +00:00
|
|
|
|
* @key_file.
|
2007-05-26 18:56:07 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: a new `GtkPaperSize` object with the restored paper size
|
2007-04-29 06:23:58 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkPaperSize *
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gtk_paper_size_new_from_key_file (GKeyFile *key_file,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *group_name,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
GError **error)
|
2007-04-29 06:23:58 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *paper_size = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *name = NULL;
|
|
|
|
|
char *ppd_name = NULL;
|
|
|
|
|
char *display_name = NULL;
|
|
|
|
|
char *freeme = NULL;
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width, height;
|
2007-04-29 06:23:58 +00:00
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (key_file != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (!group_name)
|
|
|
|
|
group_name = freeme = g_key_file_get_start_group (key_file);
|
|
|
|
|
if (!group_name || !g_key_file_has_group (key_file, group_name))
|
|
|
|
|
{
|
2008-06-19 12:47:48 +00:00
|
|
|
|
g_set_error_literal (error,
|
|
|
|
|
GTK_PRINT_ERROR,
|
|
|
|
|
GTK_PRINT_ERROR_INVALID_FILE,
|
|
|
|
|
_("Not a valid page setup file"));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define GET_DOUBLE(kf, group, name, v) \
|
|
|
|
|
v = g_key_file_get_double (kf, group, name, &err); \
|
|
|
|
|
if (err != NULL) \
|
|
|
|
|
{\
|
|
|
|
|
g_propagate_error (error, err);\
|
|
|
|
|
goto out;\
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GET_DOUBLE (key_file, group_name, "Width", width);
|
|
|
|
|
GET_DOUBLE (key_file, group_name, "Height", height);
|
|
|
|
|
|
|
|
|
|
#undef GET_DOUBLE
|
|
|
|
|
|
|
|
|
|
name = g_key_file_get_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"Name", NULL);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
ppd_name = g_key_file_get_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"PPDName", NULL);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
display_name = g_key_file_get_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"DisplayName", NULL);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
/* Fallback for old ~/.gtk-custom-paper entries */
|
|
|
|
|
if (!display_name)
|
|
|
|
|
display_name = g_strdup (name);
|
|
|
|
|
|
|
|
|
|
if (ppd_name != NULL)
|
2008-12-03 10:17:45 +00:00
|
|
|
|
paper_size = gtk_paper_size_new_from_ppd (ppd_name,
|
|
|
|
|
display_name,
|
|
|
|
|
_gtk_print_convert_from_mm (width, GTK_UNIT_POINTS),
|
|
|
|
|
_gtk_print_convert_from_mm (height, GTK_UNIT_POINTS));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
else if (name != NULL)
|
|
|
|
|
paper_size = gtk_paper_size_new_custom (name, display_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
width, height, GTK_UNIT_MM);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2008-06-19 12:47:48 +00:00
|
|
|
|
g_set_error_literal (error,
|
|
|
|
|
GTK_PRINT_ERROR,
|
|
|
|
|
GTK_PRINT_ERROR_INVALID_FILE,
|
|
|
|
|
_("Not a valid page setup file"));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2007-04-29 06:23:58 +00:00
|
|
|
|
g_assert (paper_size != NULL);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_free (ppd_name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (display_name);
|
|
|
|
|
g_free (freeme);
|
|
|
|
|
|
|
|
|
|
return paper_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_to_key_file:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @size: a `GtkPaperSize`
|
|
|
|
|
* @key_file: the `GKeyFile` to save the paper size to
|
2007-04-29 06:23:58 +00:00
|
|
|
|
* @group_name: the group to add the settings to in @key_file
|
|
|
|
|
*
|
2007-05-26 18:56:07 +00:00
|
|
|
|
* This function adds the paper size from @size to @key_file.
|
2007-04-29 06:23:58 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2007-05-26 18:56:07 +00:00
|
|
|
|
gtk_paper_size_to_key_file (GtkPaperSize *size,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
GKeyFile *key_file,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *group_name)
|
2007-04-29 06:23:58 +00:00
|
|
|
|
{
|
|
|
|
|
const char *name, *ppd_name, *display_name;
|
|
|
|
|
|
2007-05-26 18:56:07 +00:00
|
|
|
|
g_return_if_fail (size != NULL);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
g_return_if_fail (key_file != NULL);
|
|
|
|
|
|
2007-05-26 18:56:07 +00:00
|
|
|
|
name = gtk_paper_size_get_name (size);
|
|
|
|
|
display_name = gtk_paper_size_get_display_name (size);
|
|
|
|
|
ppd_name = gtk_paper_size_get_ppd_name (size);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
2011-01-13 03:30:08 +00:00
|
|
|
|
if (ppd_name != NULL)
|
2007-04-29 06:23:58 +00:00
|
|
|
|
g_key_file_set_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"PPDName", ppd_name);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
else
|
|
|
|
|
g_key_file_set_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"Name", name);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
2011-01-13 03:30:08 +00:00
|
|
|
|
if (display_name)
|
2007-04-29 06:23:58 +00:00
|
|
|
|
g_key_file_set_string (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"DisplayName", display_name);
|
2007-04-29 06:23:58 +00:00
|
|
|
|
|
|
|
|
|
g_key_file_set_double (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"Width", gtk_paper_size_get_width (size, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
g_key_file_set_double (key_file, group_name,
|
2011-01-13 03:30:08 +00:00
|
|
|
|
"Height", gtk_paper_size_get_height (size, GTK_UNIT_MM));
|
2007-04-29 06:23:58 +00:00
|
|
|
|
}
|
2016-07-07 01:31:49 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_to_gvariant:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @paper_size: a `GtkPaperSize`
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Serialize a paper size to an `a{sv}` variant.
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: (transfer none): a new, floating, `GVariant`
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*/
|
|
|
|
|
GVariant *
|
|
|
|
|
gtk_paper_size_to_gvariant (GtkPaperSize *paper_size)
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *ppd_name;
|
|
|
|
|
const char *display_name;
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
|
|
|
|
|
|
|
|
|
|
name = gtk_paper_size_get_name (paper_size);
|
|
|
|
|
ppd_name = gtk_paper_size_get_ppd_name (paper_size);
|
|
|
|
|
display_name = gtk_paper_size_get_display_name (paper_size);
|
|
|
|
|
|
|
|
|
|
if (ppd_name != NULL)
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "PPDName", g_variant_new_string (ppd_name));
|
|
|
|
|
else
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "Name", g_variant_new_string (name));
|
|
|
|
|
|
|
|
|
|
if (display_name != NULL)
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "DisplayName", g_variant_new_string (display_name));
|
|
|
|
|
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "Width", g_variant_new_double (gtk_paper_size_get_width (paper_size, GTK_UNIT_MM)));
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", "Height", g_variant_new_double (gtk_paper_size_get_height (paper_size, GTK_UNIT_MM)));
|
|
|
|
|
|
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_paper_size_new_from_gvariant:
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* @variant: an a{sv} `GVariant`
|
|
|
|
|
*
|
|
|
|
|
* Deserialize a paper size from a `GVariant`.
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* The `GVariant must be in the format produced by
|
|
|
|
|
* [method@Gtk.PaperSize.to_gvariant].
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*
|
2021-03-01 06:48:34 +00:00
|
|
|
|
* Returns: (transfer full): a new `GtkPaperSize` object
|
2016-07-07 01:31:49 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkPaperSize *
|
|
|
|
|
gtk_paper_size_new_from_gvariant (GVariant *variant)
|
|
|
|
|
{
|
|
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *ppd_name;
|
|
|
|
|
const char *display_name;
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double width, height;
|
2016-07-07 01:31:49 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (variant, "Width", "d", &width) ||
|
|
|
|
|
!g_variant_lookup (variant, "Height", "d", &height))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (variant, "Name", "&s", &name))
|
|
|
|
|
name = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (variant, "PPDName", "&s", &ppd_name))
|
|
|
|
|
ppd_name = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (variant, "DisplayName", "&s", &display_name))
|
|
|
|
|
display_name = name;
|
|
|
|
|
|
|
|
|
|
if (ppd_name != NULL)
|
|
|
|
|
paper_size = gtk_paper_size_new_from_ppd (ppd_name,
|
|
|
|
|
display_name,
|
|
|
|
|
_gtk_print_convert_from_mm (width, GTK_UNIT_POINTS),
|
|
|
|
|
_gtk_print_convert_from_mm (height, GTK_UNIT_POINTS));
|
|
|
|
|
else if (name != NULL)
|
|
|
|
|
paper_size = gtk_paper_size_new_custom (name, display_name,
|
|
|
|
|
width, height, GTK_UNIT_MM);
|
|
|
|
|
else
|
|
|
|
|
paper_size = NULL;
|
|
|
|
|
|
|
|
|
|
return paper_size;
|
|
|
|
|
}
|