File: gsfont0c.c

package info (click to toggle)
ghostscript 8.71~dfsg2-9%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 79,896 kB
  • ctags: 80,654
  • sloc: ansic: 501,432; sh: 25,689; python: 4,853; cpp: 3,633; perl: 3,597; tcl: 1,480; makefile: 1,187; lisp: 407; asm: 284; xml: 263; awk: 66; csh: 17; yacc: 15
file content (133 lines) | stat: -rw-r--r-- 4,270 bytes parent folder | download | duplicates (3)
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-2006 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 that
   license.  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.
*/

/* $Id: gsfont0c.c 8250 2007-09-25 13:31:24Z giles $ */
/* Create a FontType 0 wrapper for a CIDFont. */
#include "memory_.h"
#include "gx.h"
#include "gserrors.h"
#include "gxfont.h"
#include "gxfcid.h"
#include "gxfcmap.h"
#include "gxfont0.h"
#include "gxfont0c.h"

/* ---------------- Private ---------------- */

/* Create a Type 0 wrapper for a CIDFont/CMap pair. */
static int
type0_from_cidfont_cmap(gs_font_type0 **ppfont0, gs_font *font,
			gs_cmap_t *pcmap, int wmode, const gs_matrix *psmat,
			gs_memory_t *mem)
{
    gs_font_type0 *font0 = (gs_font_type0 *)
	gs_font_alloc(mem, &st_gs_font_type0, &gs_font_procs_default, NULL,
		      "gs_type0_from_cidfont(font)");
    /* We allocate Encoding dynamically only for the sake of the GC. */
    uint *encoding = (uint *)
	gs_alloc_bytes(mem, sizeof(uint), "gs_type0_from_cidfont(Encoding)");
    gs_font **fdep =
	gs_alloc_struct_array(mem, 1, gs_font *, &st_gs_font_ptr_element,
			      "gs_type0_from_cidfont(FDepVector)");
    int code;

    if (font0 == 0 || encoding == 0 || fdep == 0) {
	gs_free_object(mem, fdep, "gs_type0_from_cidfont(FDepVector)");
	gs_free_object(mem, encoding, "gs_type0_from_cidfont(Encoding)");
	gs_free_object(mem, font0, "gs_type0_from_cidfont(font)");
	return_error(gs_error_VMerror);
    }
    if (psmat)
	font0->FontMatrix = *psmat;
    else
	gs_make_identity(&font0->FontMatrix);
    font0->FontType = ft_composite;
    font0->procs.init_fstack = gs_type0_init_fstack;
    font0->procs.define_font = gs_no_define_font;
    font0->procs.make_font = 0; /* not called */
    font0->procs.next_char_glyph = gs_type0_next_char_glyph;
    font0->key_name = font->key_name;
    font0->font_name = font->font_name;
    font0->data.FMapType = fmap_CMap;
    encoding[0] = 0;
    font0->data.Encoding = encoding;
    font0->data.encoding_size = 1;
    fdep[0] = font;
    font0->data.FDepVector = fdep;
    font0->data.fdep_size = 1;
    font0->data.CMap = pcmap;
    font0->data.SubsVector.data = 0;
    font0->data.SubsVector.size = 0;
    code = gs_definefont(font->dir, (gs_font *)font0);
    if (code < 0)
	return code;
    *ppfont0 = font0;
    return 0;
}

/* ---------------- Public entries ---------------- */

/* Create a Type 0 wrapper for a CIDFont. */
int
gs_font_type0_from_cidfont(gs_font_type0 **ppfont0, gs_font *font, int wmode,
			   const gs_matrix *psmat, gs_memory_t *mem)
{
    gs_cmap_t *pcmap;
    int code = gs_cmap_create_identity(&pcmap, 2, wmode, mem);

    if (code < 0)
	return code;
    code = type0_from_cidfont_cmap(ppfont0, font, pcmap, wmode, psmat, mem);
    if (code < 0) {
	gs_free_object(mem, pcmap, "gs_font_type0_from_cidfont(CMap)");
	/****** FREE SUBSTRUCTURES -- HOW? ******/
    }
    return code;
}

/*
 * Create a Type 0 font wrapper for a Type 42 font (converted to a Type 2
 * CIDFont), optionally using the TrueType cmap as the CMap.
 * See gs_cmap_from_type42_cmap for details.
 */
int
gs_font_type0_from_type42(gs_font_type0 **ppfont0, gs_font_type42 *pfont42,
			  int wmode, bool use_cmap, gs_memory_t *mem)
{
    gs_font_cid2 *pfcid;
    gs_font_type0 *pfont0;
    int code = gs_font_cid2_from_type42(&pfcid, pfont42, wmode, mem);

    if (code < 0)
	return code;
    if (use_cmap) {
	gs_cmap_t *pcmap;

	code = gs_cmap_from_type42_cmap(&pcmap, pfont42, wmode, mem);
	if (code < 0)
	    return code;
	code = type0_from_cidfont_cmap(&pfont0, (gs_font *)pfcid, pcmap,
				       wmode, NULL, mem);
    } else {
	code = gs_font_type0_from_cidfont(&pfont0, (gs_font *)pfcid, wmode,
					  NULL, mem);
    }
    if (code < 0) {
	gs_free_object(mem, pfcid, "gs_type0_from_type42(CIDFont)");
	/****** FREE SUBSTRUCTURES -- HOW? ******/
	return code;
    }

    *ppfont0 = pfont0;
    return 0;
}