Line data Source code
1 : /* Copyright 1989-2024 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : #ifdef HAVE_CONFIG_H 20 : #include <config.h> 21 : #endif 22 : 23 : #include <assert.h> // assert() 24 : #include <stdio.h> // snprintf() 25 : #include <string.h> // strchr(), strlen() 26 : 27 : #include "lib.h" 28 : 29 : #include "font.h" 30 : #include "searchpath.h" 31 : #include "device.h" 32 : #include "defs.h" 33 : 34 : const char *const FONT_ENV_VAR = "GROFF_FONT_PATH"; 35 : 36 : static search_path font_path(FONT_ENV_VAR, FONTPATH, 0, 0); 37 : 38 : int font::res = 0; 39 : int font::hor = 1; 40 : int font::vert = 1; 41 : int font::unitwidth = 0; 42 : int font::paperwidth = 0; 43 : int font::paperlength = 0; 44 : const char *font::papersize = 0; 45 : int font::biggestfont = 0; 46 : int font::spare2 = 0; 47 : int font::sizescale = 1; 48 : bool font::has_tcommand = false; 49 : bool font::pass_filenames = false; 50 : bool font::use_unscaled_charwidths = false; 51 : bool font::use_charnames_in_special = false; 52 : bool font::is_unicode = false; 53 : const char *font::image_generator = 0; 54 : const char **font::font_name_table = 0; 55 : int *font::sizes = 0; 56 : const char *font::family = 0; 57 : const char **font::style_table = 0; 58 : FONT_COMMAND_HANDLER font::unknown_desc_command_handler = 0; 59 : 60 136 : void font::command_line_font_dir(const char *dir) 61 : { 62 136 : font_path.command_line_dir(dir); 63 136 : } 64 : 65 24422 : FILE *font::open_file(const char *nm, char **pathp) 66 : { 67 24422 : assert(nm != 0 /* nullptr */); 68 24422 : assert(device != 0 /* nullptr */); 69 24422 : FILE *fp = 0 /* nullptr */; 70 : // Do not traverse user-specified directories; Savannah #61424. 71 24422 : if ((0 /* nullptr */ == strchr(nm, '/')) 72 24421 : && (device != 0 /* nullptr */) && (nm != 0 /* nullptr */)) { 73 : // Allocate enough for nm + device + 'dev' '/' '\0'. 74 24421 : size_t expected_size = strlen(nm) + strlen(device) + 5; 75 24421 : char *filename = new char[expected_size]; 76 24421 : const size_t actual_size = snprintf(filename, expected_size, 77 24421 : "dev%s/%s", device, nm); 78 24421 : expected_size--; // snprintf() doesn't count the null terminator. 79 24421 : if (actual_size == expected_size) 80 24421 : fp = font_path.open_file(filename, pathp); 81 24421 : delete[] filename; 82 : } 83 24422 : return fp; 84 : } 85 : 86 56 : FILE *font::open_resource_file(const char *nm, char **pathp) 87 : { 88 56 : assert(nm != 0 /* nullptr */); 89 56 : assert(device != 0 /* nullptr */); 90 56 : FILE *fp = 0 /* nullptr */; 91 56 : if ((device != 0 /* nullptr */) && (nm != 0 /* nullptr */)) { 92 : // Allocate enough for nm + device + 'dev' '/' '\0'. 93 56 : size_t expected_size = strlen(nm) + strlen(device) + 5; 94 56 : char *filename = new char[expected_size]; 95 56 : const size_t actual_size = snprintf(filename, expected_size, 96 56 : "dev%s/%s", device, nm); 97 56 : expected_size--; // snprintf() doesn't count the null terminator. 98 56 : if (actual_size == expected_size) 99 56 : fp = font_path.open_file(filename, pathp); 100 56 : delete[] filename; 101 : } 102 56 : return fp; 103 : } 104 : 105 : // Local Variables: 106 : // fill-column: 72 107 : // mode: C++ 108 : // End: 109 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: