[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 24/26: [libgroff]: Add `font::open_resource_file()`.
From: |
G. Branden Robinson |
Subject: |
[groff] 24/26: [libgroff]: Add `font::open_resource_file()`. |
Date: |
Thu, 14 Nov 2024 11:54:13 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 2b9d309c8176801789f7a7011fc6cef7ffa9f2b9
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Nov 14 09:57:27 2024 -0600
[libgroff]: Add `font::open_resource_file()`.
* src/include/font.h (class font): Declare new `open_resource_file()`
member function with same interface as `open_file()`, but intended to
open arbitrary file specifications instead of only files within
groff's font search path. This is for use by drivers that need to
embed auxiliary files in their output, such as font files for
PostScript (contrast these with groff's font _description_ files).
* src/libs/libgroff/fontfile.cpp (font::open_resource_file): Implement
new function.
---
ChangeLog | 12 ++++++++++++
src/include/font.h | 28 ++++++++++++++++++----------
src/libs/libgroff/fontfile.cpp | 19 +++++++++++++++++++
3 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 88a158ce1..31a29fb59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-11-14 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/include/font.h (class font): Declare new
+ `open_resource_file()` member function with same interface as
+ `open_file()`, but intended to open arbitrary file
+ specifications instead of only files within groff's font search
+ path. This is for use by drivers that need to embed auxiliary
+ files in their output, such as font files for PostScript
+ {contrast these with groff's font _description_ files}.
+ * src/libs/libgroff/fontfile.cpp (font::open_resource_file):
+ Implement new function.
+
2024-11-14 G. Branden Robinson <g.branden.robinson@gmail.com>
* m4/groff.m4 (GROFF_CHECK_VERSION_FORMAT): Use a _basic_ (not
diff --git a/src/include/font.h b/src/include/font.h
index 4e447f4d5..9742a383a 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -1,5 +1,4 @@
-// -*- C++ -*-
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -212,14 +211,23 @@ public:
static void command_line_font_dir(const char *); // Prepend given
// path (arg1) to the list of directories in which
// to look up fonts.
- static FILE *open_file(const char *, char **); // Open
- // a font file with the given name (arg1),
- // searching along the current font path. If
- // arg2 points to a string pointer, set it to
- // the found file name (this depends on the
- // device also). Return the opened file. If
- // not found, arg2 is unchanged, and a null
- // pointer is returned.
+ static FILE *open_file(const char *, char **); // Open a font
+ // description file with the given name (arg1),
+ // searching along the current font path, and
+ // rejecting `arg1` if it contains a slash (see
+ // Savannah #61424). If arg2 points to a string
+ // pointer, set it to the found file name (this
+ // depends on the device also). Return the
+ // opened file's stream pointer. If not found,
+ // arg2 is unchanged, and a null pointer is
+ // returned.
+ static FILE *open_resource_file(const char *, char **); // Open an
+ // externally supplied (non-groff) file required
+ // by the output driver, possibly to embed
+ // content in the generated file. Like
+ // `open_file()` except that it accepts slashes
+ // in `arg1`. Examples include Type 1 fonts
+ // embedded in PostScript output.
// Open the DESC file (depending on the device) and initialize some
// static variables with info from there.
diff --git a/src/libs/libgroff/fontfile.cpp b/src/libs/libgroff/fontfile.cpp
index 7585fc55d..aa4f32eca 100644
--- a/src/libs/libgroff/fontfile.cpp
+++ b/src/libs/libgroff/fontfile.cpp
@@ -83,6 +83,25 @@ FILE *font::open_file(const char *nm, char **pathp)
return fp;
}
+FILE *font::open_resource_file(const char *nm, char **pathp)
+{
+ assert(nm != 0 /* nullptr */);
+ assert(device != 0 /* nullptr */);
+ FILE *fp = 0 /* nullptr */;
+ if ((device != 0 /* nullptr */) && (nm != 0 /* nullptr */)) {
+ // Allocate enough for nm + device + 'dev' '/' '\0'.
+ size_t expected_size = strlen(nm) + strlen(device) + 5;
+ char *filename = new char[expected_size];
+ const size_t actual_size = snprintf(filename, expected_size,
+ "dev%s/%s", device, nm);
+ expected_size--; // snprintf() doesn't count the null terminator.
+ if (actual_size == expected_size)
+ fp = font_path.open_file(filename, pathp);
+ delete[] filename;
+ }
+ return fp;
+}
+
// Local Variables:
// fill-column: 72
// mode: C++
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 24/26: [libgroff]: Add `font::open_resource_file()`.,
G. Branden Robinson <=