mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-04-22 08:26:47 +02:00
Compare commits
3 Commits
1cec42f399
...
138f3955d1
Author | SHA1 | Date | |
---|---|---|---|
|
138f3955d1 | ||
|
82844ad2ce | ||
|
d7cce4dfbc |
55
testpdfio.c
55
testpdfio.c
@ -27,7 +27,7 @@
|
||||
//
|
||||
|
||||
static int do_crypto_tests(void);
|
||||
static int do_test_file(const char *filename, int objnum, bool verbose);
|
||||
static int do_test_file(const char *filename, int objnum, const char *password, bool verbose);
|
||||
static int do_unit_tests(void);
|
||||
static int draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label);
|
||||
static bool error_cb(pdfio_file_t *pdf, const char *message, bool *error);
|
||||
@ -37,6 +37,7 @@ static const char *password_cb(void *data, const char *filename);
|
||||
static int read_unit_file(const char *filename, size_t num_pages, size_t first_image, bool is_output);
|
||||
static ssize_t token_consume_cb(const char **s, size_t bytes);
|
||||
static ssize_t token_peek_cb(const char **s, char *buffer, size_t bytes);
|
||||
static int usage(FILE *fp);
|
||||
static int verify_image(pdfio_file_t *pdf, size_t number);
|
||||
static int write_alpha_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
||||
static int write_color_patch(pdfio_stream_t *st, bool device);
|
||||
@ -62,19 +63,30 @@ main(int argc, // I - Number of command-line arguments
|
||||
int ret = 0; // Return value
|
||||
|
||||
|
||||
fprintf(stderr, "testpdfio: Test locale is \"%s\".\n", setlocale(LC_ALL, getenv("LANG")));
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
int i; // Looping var
|
||||
const char *password = NULL; // Password
|
||||
bool verbose = false; // Be verbose?
|
||||
|
||||
for (i = 1; i < argc; i ++)
|
||||
{
|
||||
if (!strcmp(argv[i], "--help"))
|
||||
{
|
||||
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
|
||||
return (0);
|
||||
return (usage(stdout));
|
||||
}
|
||||
else if (!strcmp(argv[i], "--password"))
|
||||
{
|
||||
i ++;
|
||||
if (i < argc)
|
||||
{
|
||||
password = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs("testpdfio: Missing password after '--password'.\n", stderr);
|
||||
return (usage(stderr));
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[i], "--verbose"))
|
||||
{
|
||||
@ -82,24 +94,27 @@ main(int argc, // I - Number of command-line arguments
|
||||
}
|
||||
else if (argv[i][0] == '-')
|
||||
{
|
||||
printf("Unknown option '%s'.\n\n", argv[i]);
|
||||
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
|
||||
return (1);
|
||||
fprintf(stderr, "testpdfio: Unknown option '%s'.\n", argv[i]);
|
||||
return (usage(stderr));
|
||||
}
|
||||
else if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
|
||||
{
|
||||
// filename.pdf object-number
|
||||
if (do_test_file(argv[i], atoi(argv[i + 1]), verbose))
|
||||
if (do_test_file(argv[i], atoi(argv[i + 1]), password, verbose))
|
||||
ret = 1;
|
||||
|
||||
i ++;
|
||||
}
|
||||
else if (do_test_file(argv[i], 0, verbose))
|
||||
else if (do_test_file(argv[i], 0, password, verbose))
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "testpdfio: Test locale is \"%s\".\n", setlocale(LC_ALL, getenv("LANG")));
|
||||
|
||||
#if _WIN32
|
||||
// Windows puts executables in Platform/Configuration subdirs...
|
||||
if (!_access("../../testfiles", 0))
|
||||
@ -363,6 +378,7 @@ do_crypto_tests(void)
|
||||
static int // O - Exit status
|
||||
do_test_file(const char *filename, // I - PDF filename
|
||||
int objnum, // I - Object number to dump, if any
|
||||
const char *password, // I - Password for file
|
||||
bool verbose) // I - Be verbose?
|
||||
{
|
||||
bool error = false; // Have we shown an error yet?
|
||||
@ -381,7 +397,7 @@ do_test_file(const char *filename, // I - PDF filename
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if ((pdf = pdfioFileOpen(filename, /*password_cb*/NULL, /*password_data*/NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||
if ((pdf = pdfioFileOpen(filename, password_cb, (void *)password, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||
{
|
||||
if (objnum)
|
||||
{
|
||||
@ -1559,6 +1575,23 @@ token_peek_cb(const char **s, // IO - Test string
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'usage()' - Show program usage.
|
||||
//
|
||||
|
||||
static int // O - Exit status
|
||||
usage(FILE *fp) // I - Output file
|
||||
{
|
||||
fputs("Usage: ./testpdfio [OPTIONS] [FILENAME [OBJNUM]] ...\n", fp);
|
||||
fputs("Options:\n", fp);
|
||||
fputs(" --help Show program help.\n", fp);
|
||||
fputs(" --password PASSWORD Set PDF password.\n", fp);
|
||||
fputs(" --verbose Be verbose.\n", fp);
|
||||
|
||||
return (fp != stdout);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 'verify_image()' - Verify an image object.
|
||||
//
|
||||
|
@ -3,7 +3,7 @@
|
||||
//
|
||||
// https://github.com/michaelrsweet/ttf
|
||||
//
|
||||
// Copyright © 2018-2023 by Michael R Sweet.
|
||||
// Copyright © 2018-2024 by Michael R Sweet.
|
||||
//
|
||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||
// information.
|
||||
@ -120,6 +120,7 @@ test_font(const char *filename) // I - Font filename
|
||||
|
||||
|
||||
printf("ttfCreate(\"%s\"): ", filename);
|
||||
fflush(stdout);
|
||||
if ((font = ttfCreate(filename, 0, error_cb, NULL)) != NULL)
|
||||
puts("PASS");
|
||||
else
|
||||
|
36
ttf.c
36
ttf.c
@ -62,7 +62,7 @@
|
||||
# define O_CREAT _O_CREAT
|
||||
# define O_TRUNC _O_TRUNC
|
||||
|
||||
typedef __int64 ssize_t; // POSIX type not present on Windows...
|
||||
typedef __int64 ssize_t; // POSIX type not present on Windows... @private@
|
||||
|
||||
#else
|
||||
# include <unistd.h>
|
||||
@ -299,7 +299,28 @@ static unsigned seek_table(ttf_t *font, unsigned tag, unsigned offset, bool requ
|
||||
|
||||
|
||||
//
|
||||
// 'ttfCreate()' - Create a new font object for the named font family.
|
||||
// 'ttfCreate()' - Create a new font object for the named font file.
|
||||
//
|
||||
// This function creates a new font object for the named TrueType or OpenType
|
||||
// font file or collection. The "filename" argument specifies the name of the
|
||||
// file to read.
|
||||
//
|
||||
// The "idx" argument specifies the font to load from a collection - the first
|
||||
// font is number `0`. Once created, you can call the @link ttfGetNumFonts@
|
||||
// function to determine whether the loaded font file is a collection with more
|
||||
// than one font.
|
||||
//
|
||||
// The "err_cb" and "err_data" arguments specify a callback function and data
|
||||
// pointer for receiving error messages. If `NULL`, errors are sent to the
|
||||
// `stderr` file. The callback function receives the data pointer and a text
|
||||
// message string, for example:
|
||||
//
|
||||
// ```
|
||||
// void my_err_cb(void *err_data, const char *message)
|
||||
// {
|
||||
// fprintf(stderr, "ERROR: %s\n", message);
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
|
||||
ttf_t * // O - New font object
|
||||
@ -552,6 +573,10 @@ ttfGetAscent(ttf_t *font) // I - Font
|
||||
//
|
||||
// 'ttfGetBounds()' - Get the bounds of all characters in a font.
|
||||
//
|
||||
// This function gets the bounds of all characters in a font. The "bounds"
|
||||
// argument is a pointer to a `ttf_rect_t` structure that will be filled with
|
||||
// the limits for characters in the font scaled to a 1000x1000 unit square.
|
||||
//
|
||||
|
||||
ttf_rect_t * // O - Bounds or `NULL` on error
|
||||
ttfGetBounds(ttf_t *font, // I - Font
|
||||
@ -633,8 +658,11 @@ ttfGetDescent(ttf_t *font) // I - Font
|
||||
//
|
||||
// 'ttfGetExtents()' - Get the extents of a UTF-8 string.
|
||||
//
|
||||
// This function computes the extents of a UTF-8 string when rendered using the
|
||||
// specified font and size.
|
||||
// This function computes the extents of the UTF-8 string "s" when rendered
|
||||
// using the specified font "font" and size "size". The "extents" argument is
|
||||
// a pointer to a `ttf_rect_t` structure that is filled with the extents of a
|
||||
// simple rendering of the string with no kerning or rewriting applied. The
|
||||
// values are scaled using the specified font size.
|
||||
//
|
||||
|
||||
ttf_rect_t * // O - Pointer to extents or `NULL` on error
|
||||
|
16
ttf.h
16
ttf.h
@ -3,7 +3,7 @@
|
||||
//
|
||||
// https://github.com/michaelrsweet/ttf
|
||||
//
|
||||
// Copyright © 2018-2023 by Michael R Sweet.
|
||||
// Copyright © 2018-2024 by Michael R Sweet.
|
||||
//
|
||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||
// information.
|
||||
@ -22,12 +22,12 @@ extern "C" {
|
||||
// Types...
|
||||
//
|
||||
|
||||
typedef struct _ttf_s ttf_t; //// Font object
|
||||
typedef struct _ttf_s ttf_t; // Font object
|
||||
|
||||
typedef void (*ttf_err_cb_t)(void *data, const char *message);
|
||||
//// Font error callback
|
||||
// Font error callback
|
||||
|
||||
typedef enum ttf_stretch_e //// Font stretch
|
||||
typedef enum ttf_stretch_e // Font stretch
|
||||
{
|
||||
TTF_STRETCH_NORMAL, // normal
|
||||
TTF_STRETCH_ULTRA_CONDENSED, // ultra-condensed
|
||||
@ -40,20 +40,20 @@ typedef enum ttf_stretch_e //// Font stretch
|
||||
TTF_STRETCH_ULTRA_EXPANDED // ultra-expanded
|
||||
} ttf_stretch_t;
|
||||
|
||||
typedef enum ttf_style_e //// Font style
|
||||
typedef enum ttf_style_e // Font style
|
||||
{
|
||||
TTF_STYLE_NORMAL, // Normal font
|
||||
TTF_STYLE_ITALIC, // Italic font
|
||||
TTF_STYLE_OBLIQUE // Oblique (angled) font
|
||||
} ttf_style_t;
|
||||
|
||||
typedef enum ttf_variant_e //// Font variant
|
||||
typedef enum ttf_variant_e // Font variant
|
||||
{
|
||||
TTF_VARIANT_NORMAL, // Normal font
|
||||
TTF_VARIANT_SMALL_CAPS // Font whose lowercase letters are small capitals
|
||||
} ttf_variant_t;
|
||||
|
||||
typedef enum ttf_weight_e //// Font weight
|
||||
typedef enum ttf_weight_e // Font weight
|
||||
{
|
||||
TTF_WEIGHT_100 = 100, // Weight 100 (Thin)
|
||||
TTF_WEIGHT_200 = 200, // Weight 200 (Extra/Ultra-Light)
|
||||
@ -66,7 +66,7 @@ typedef enum ttf_weight_e //// Font weight
|
||||
TTF_WEIGHT_900 = 900 // Weight 900 (Black/Heavy)
|
||||
} ttf_weight_t;
|
||||
|
||||
typedef struct ttf_rect_s //// Bounding rectangle
|
||||
typedef struct ttf_rect_s // Bounding rectangle
|
||||
{
|
||||
float left; // Left offset
|
||||
float top; // Top offset
|
||||
|
Loading…
x
Reference in New Issue
Block a user