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
|
/* Copyright (C) 2001-2012 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
Refer to licensing information at http://www.artifex.com or contact
Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
/* this is the ps interpreter interface to the native font
enumeration code. it calls the platform-specific routines
to obtain an additional set of entries that can be added
to the Fontmap to reference fonts stored on the system.
*/
#include "memory_.h"
#include "string_.h"
#include <stdlib.h>
#include "ghost.h"
#include "oper.h"
#include "gsstruct.h"
#include "gsmalloc.h"
#include "ialloc.h"
#include "iname.h"
#include "iutil.h"
#include "store.h"
#include "gp.h"
typedef struct fontenum_s {
char *fontname, *path;
struct fontenum_s *next;
} fontenum_t;
/* .getnativefonts [ [<name> <path>] ... ] */
static int
z_fontenum(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
void *enum_state;
int code = 0;
int e,elements;
char *fontname, *path;
fontenum_t *r, *results;
ref array;
uint length;
byte *string;
enum_state = gp_enumerate_fonts_init(imemory);
if (enum_state == NULL) {
/* put false on the stack and return */
push(1);
make_bool(op, false);
return code;
}
r = results = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list");
elements = 0;
while((code = gp_enumerate_fonts_next(enum_state, &fontname, &path )) > 0) {
if (fontname == NULL || path == NULL) {
gp_enumerate_fonts_free(enum_state);
return_error(e_ioerror);
}
length = strlen(fontname) + 1;
r->fontname = gs_malloc(imemory->non_gc_memory, length, 1, "native font name");
memcpy(r->fontname, fontname, length);
length = strlen(path) + 1;
r->path = gs_malloc(imemory->non_gc_memory, length, 1, "native font path");
memcpy(r->path, path, length);
r->next = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list");
r = r->next;
elements += 1;
}
gp_enumerate_fonts_free(enum_state);
code = ialloc_ref_array(&array, a_all | icurrent_space, elements, "native fontmap");
r = results;
for (e = 0; e < elements; e++) {
ref mapping;
code = ialloc_ref_array(&mapping, a_all | icurrent_space, 2, "native font mapping");
length = strlen(r->fontname);
string = ialloc_string(length, "native font name");
if (string == NULL)
return_error(e_VMerror);
memcpy(string, r->fontname, length);
make_string(&(mapping.value.refs[0]), a_all | icurrent_space, length, string);
length = strlen(r->path);
string = ialloc_string(length, "native font path");
if (string == NULL)
return_error(e_VMerror);
memcpy(string, r->path, length);
make_string(&(mapping.value.refs[1]), a_all | icurrent_space, length, string);
ref_assign(&(array.value.refs[e]), &mapping);
results = r;
r = r->next;
gs_free(imemory->non_gc_memory,
results->fontname, strlen(results->fontname) + 1, 1, "native font name");
gs_free(imemory->non_gc_memory,
results->path, strlen(results->path) + 1, 1, "native font path");
gs_free(imemory->non_gc_memory,
results, 1, sizeof(fontenum_t), "fontenum list");
}
push(2);
ref_assign(op-1, &array);
make_bool(op, true);
return code;
}
/* Match the above routines to their postscript filter names.
This is how our static routines get called externally. */
const op_def zfontenum_op_defs[] = {
{"0.getnativefonts", z_fontenum},
op_def_end(0)
};
|