Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 2002 Aladdin Enterprises.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gsfont0c.c,v 1.4 2002/09/08 20:29:07 igor Exp $ */
18
/* Create a FontType 0 wrapper for a CIDFont. */
19
#include "memory_.h"
20
#include "gx.h"
21
#include "gserrors.h"
22
#include "gxfont.h"
23
#include "gxfcid.h"
24
#include "gxfcmap.h"
25
#include "gxfont0.h"
26
#include "gxfont0c.h"
27
 
28
/* ---------------- Private ---------------- */
29
 
30
/* Create a Type 0 wrapper for a CIDFont/CMap pair. */
31
private int
32
type0_from_cidfont_cmap(gs_font_type0 **ppfont0, gs_font *font,
33
			gs_cmap_t *pcmap, int wmode, const gs_matrix *psmat,
34
			gs_memory_t *mem)
35
{
36
    gs_font_type0 *font0 = (gs_font_type0 *)
37
	gs_font_alloc(mem, &st_gs_font_type0, &gs_font_procs_default, NULL,
38
		      "gs_type0_from_cidfont(font)");
39
    /* We allocate Encoding dynamically only for the sake of the GC. */
40
    uint *encoding = (uint *)
41
	gs_alloc_bytes(mem, sizeof(uint), "gs_type0_from_cidfont(Encoding)");
42
    gs_font **fdep =
43
	gs_alloc_struct_array(mem, 1, gs_font *, &st_gs_font_ptr_element,
44
			      "gs_type0_from_cidfont(FDepVector)");
45
    int code;
46
 
47
    if (font0 == 0 || encoding == 0 || fdep == 0) {
48
	gs_free_object(mem, fdep, "gs_type0_from_cidfont(FDepVector)");
49
	gs_free_object(mem, encoding, "gs_type0_from_cidfont(Encoding)");
50
	gs_free_object(mem, font0, "gs_type0_from_cidfont(font)");
51
	return_error(gs_error_VMerror);
52
    }
53
    if (psmat)
54
	font0->FontMatrix = *psmat;
55
    else
56
	gs_make_identity(&font0->FontMatrix);
57
    font0->FontType = ft_composite;
58
    font0->procs.init_fstack = gs_type0_init_fstack;
59
    font0->procs.define_font = gs_no_define_font;
60
    font0->procs.make_font = 0; /* not called */
61
    font0->procs.next_char_glyph = gs_type0_next_char_glyph;
62
    font0->key_name = font->key_name;
63
    font0->font_name = font->font_name;
64
    font0->data.FMapType = fmap_CMap;
65
    encoding[0] = 0;
66
    font0->data.Encoding = encoding;
67
    font0->data.encoding_size = 1;
68
    fdep[0] = font;
69
    font0->data.FDepVector = fdep;
70
    font0->data.fdep_size = 1;
71
    font0->data.CMap = pcmap;
72
    font0->data.SubsVector.data = 0;
73
    font0->data.SubsVector.size = 0;
74
    code = gs_definefont(font->dir, (gs_font *)font0);
75
    if (code < 0)
76
	return code;
77
    *ppfont0 = font0;
78
    return 0;
79
}
80
 
81
/* ---------------- Public entries ---------------- */
82
 
83
/* Create a Type 0 wrapper for a CIDFont. */
84
int
85
gs_font_type0_from_cidfont(gs_font_type0 **ppfont0, gs_font *font, int wmode,
86
			   const gs_matrix *psmat, gs_memory_t *mem)
87
{
88
    gs_cmap_t *pcmap;
89
    int code = gs_cmap_create_identity(&pcmap, 2, wmode, mem);
90
 
91
    if (code < 0)
92
	return code;
93
    code = type0_from_cidfont_cmap(ppfont0, font, pcmap, wmode, psmat, mem);
94
    if (code < 0) {
95
	gs_free_object(mem, pcmap, "gs_font_type0_from_cidfont(CMap)");
96
	/****** FREE SUBSTRUCTURES -- HOW? ******/
97
    }
98
    return code;
99
}
100
 
101
/*
102
 * Create a Type 0 font wrapper for a Type 42 font (converted to a Type 2
103
 * CIDFont), optionally using the TrueType cmap as the CMap.
104
 * See gs_cmap_from_type42_cmap for details.
105
 */
106
int
107
gs_font_type0_from_type42(gs_font_type0 **ppfont0, gs_font_type42 *pfont42,
108
			  int wmode, bool use_cmap, gs_memory_t *mem)
109
{
110
    gs_font_cid2 *pfcid;
111
    gs_font_type0 *pfont0;
112
    int code = gs_font_cid2_from_type42(&pfcid, pfont42, wmode, mem);
113
 
114
    if (code < 0)
115
	return code;
116
    if (use_cmap) {
117
	gs_cmap_t *pcmap;
118
 
119
	code = gs_cmap_from_type42_cmap(&pcmap, pfont42, wmode, mem);
120
	if (code < 0)
121
	    return code;
122
	code = type0_from_cidfont_cmap(&pfont0, (gs_font *)pfcid, pcmap,
123
				       wmode, NULL, mem);
124
    } else {
125
	code = gs_font_type0_from_cidfont(&pfont0, (gs_font *)pfcid, wmode,
126
					  NULL, mem);
127
    }
128
    if (code < 0) {
129
	gs_free_object(mem, pfcid, "gs_type0_from_type42(CIDFont)");
130
	/****** FREE SUBSTRUCTURES -- HOW? ******/
131
	return code;
132
    }
133
 
134
    *ppfont0 = pfont0;
135
    return 0;
136
}