1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
Paper sizes command-line utility.
Copyright (c) 2021-2023 Reuben Thomas <rrt@sc3d.org>.
This library is API/ABI-compatible with that of the original libpaper by
Yves Arrouye <Yves.Arrouye@marin.fdn.fr>, 1996, but it lacks the following
APIs: defaultpapersizefile, systempapersizefile, paperlast, paperprev.
This file is part of libpaper.
This program is free software: you can redistribute it and/or modify it
under the terms of the MIT license.
This program 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.
*/
#ifndef PAPER_H
#define PAPER_H
#include <stddef.h>
/* Allow the include file to be used directly from C++. */
#ifdef __cplusplus
extern "C" {
#endif
/* Opaque struct. */
struct paper;
enum paper_unit {
PAPER_UNIT_PT,
PAPER_UNIT_MM,
PAPER_UNIT_IN,
PAPER_NUM_UNITS,
PAPER_UNIT_INVALID = -1
};
enum paper_error {
PAPER_OK,
PAPER_BAD_WIDTH,
PAPER_BAD_HEIGHT,
PAPER_BAD_UNIT,
PAPER_MISSING_FIELD,
PAPER_NOMEM = -1
};
extern size_t paper_lineno;
extern char *paper_specsfile;
/*
* Initialize the library, and read configured paper sizes.
* This function must be called before any other in the library.
* Returns a paper_error value (PAPER_OK for success).
*/
int paperinit(void);
/*
* Free any resources allocated by paperinit().
* After calling it, no other library function may be called, except
* paperinit().
* Returns a paper_error value (PAPER_OK for success).
*/
int paperdone(void);
/*
* Return the name of the given paper.
*/
const char *papername(const struct paper *paper);
/*
* Return the width of the given paper in its natural units.
*/
double paperwidth(const struct paper *paper);
/*
* Return the height of the given paper in its natural units.
*/
double paperheight(const struct paper *paper);
/*
* Return the natural unit of the given paper.
*/
enum paper_unit paperunit(const struct paper *paper);
/*
* Return the width of the given paper in PostScript points.
*/
double paperpswidth(const struct paper *paper);
/*
* Return the height of the given paper in PostScript points.
*/
double paperpsheight(const struct paper *paper);
/*
* Look up a paper size by name (case-insensitive).
* Return the paper if found, or NULL if not.
*/
const struct paper *paperinfo(const char *papername);
/*
* Look up a paper size by size (in PostScript points).
* Return the paper if found, or NULL if not.
*/
const struct paper *paperwithsize(double pswidth, double psheight);
/*
* Returns the current paper size, as specified in paper(1), or NULL if none
* can be determined.
*/
const struct paper *defaultpaper(void);
/*
* Deprecated, only for backwards compatibility. Returns the default
* configured paper name.
*/
const char *defaultpapername(void);
/*
* Deprecated, only for backwards compatibility; does the same as
* defaultpapername(), but returns a value that must be freed.
*/
char *systempapername(void);
/*
* Return the first paper in the list of known paper sizes.
*/
const struct paper *paperfirst(void);
/*
* Return the next paper in the list of known paper sizes.
*/
const struct paper *papernext(const struct paper *paper);
/*
* Return the name of the given unit.
*/
const char *paperunitname(enum paper_unit n);
/*
* Return the conversion factor from pts to the given unit.
*/
double paperunitfactor(enum paper_unit n);
/*
* Return the unit with the given name.
*/
enum paper_unit paperunitfromname(const char *name);
/*
* Set prefix dir for the library for systems that can't auto-detect it.
*/
void papersetprefixdir(const char *new_prefix);
#ifdef __cplusplus
}
#endif
#endif
|