2 * PostScript driver downloadable font functions
4 * Copyright 2002 Huw D M Davies for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
39 /****************************************************************************
42 static void get_download_name(PSDRV_PDEVICE
*physDev
, LPOUTLINETEXTMETRICA
47 len
= strlen((char*)potm
+ (ptrdiff_t)potm
->otmpFullName
) + 1;
48 *str
= HeapAlloc(GetProcessHeap(),0,len
);
49 strcpy(*str
, (char*)potm
+ (ptrdiff_t)potm
->otmpFullName
);
52 while((p
= strchr(p
, ' ')))
58 /****************************************************************************
61 static DOWNLOAD
*is_font_downloaded(PSDRV_PDEVICE
*physDev
, char *ps_name
)
65 for(pdl
= physDev
->downloaded_fonts
; pdl
; pdl
= pdl
->next
)
66 if(!strcmp(pdl
->ps_name
, ps_name
))
71 /****************************************************************************
74 static BOOL
is_room_for_font(PSDRV_PDEVICE
*physDev
)
79 /* FIXME: should consider vm usage of each font and available printer memory.
80 For now we allow upto two fonts to be downloaded at a time */
81 for(pdl
= physDev
->downloaded_fonts
; pdl
; pdl
= pdl
->next
)
89 /****************************************************************************
90 * PSDRV_SelectDownloadFont
92 * Set up physDev->font for a downloadable font
95 BOOL
PSDRV_SelectDownloadFont(PSDRV_PDEVICE
*physDev
)
98 LPOUTLINETEXTMETRICA potm
;
99 DWORD len
= GetOutlineTextMetricsA(physDev
->hdc
, 0, NULL
);
101 potm
= HeapAlloc(GetProcessHeap(), 0, len
);
102 GetOutlineTextMetricsA(physDev
->hdc
, len
, potm
);
103 get_download_name(physDev
, potm
, &ps_name
);
105 physDev
->font
.fontloc
= Download
;
106 physDev
->font
.fontinfo
.Download
= is_font_downloaded(physDev
, ps_name
);
108 physDev
->font
.size
= INTERNAL_YWSTODS(physDev
->dc
, /* ppem */
109 potm
->otmTextMetrics
.tmAscent
+
110 potm
->otmTextMetrics
.tmDescent
-
111 potm
->otmTextMetrics
.tmInternalLeading
);
112 physDev
->font
.underlineThickness
= potm
->otmsUnderscoreSize
;
113 physDev
->font
.underlinePosition
= potm
->otmsUnderscorePosition
;
114 physDev
->font
.strikeoutThickness
= potm
->otmsStrikeoutSize
;
115 physDev
->font
.strikeoutPosition
= potm
->otmsStrikeoutPosition
;
117 HeapFree(GetProcessHeap(), 0, ps_name
);
118 HeapFree(GetProcessHeap(), 0, potm
);
122 /****************************************************************************
123 * PSDRV_WriteSetDownloadFont
125 * Write setfont for download font.
128 BOOL
PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE
*physDev
)
131 LPOUTLINETEXTMETRICA potm
;
132 DWORD len
= GetOutlineTextMetricsA(physDev
->hdc
, 0, NULL
);
135 assert(physDev
->font
.fontloc
== Download
);
137 potm
= HeapAlloc(GetProcessHeap(), 0, len
);
138 GetOutlineTextMetricsA(physDev
->hdc
, len
, potm
);
140 get_download_name(physDev
, potm
, &ps_name
);
142 if(physDev
->font
.fontinfo
.Download
== NULL
) {
143 pdl
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pdl
));
144 pdl
->ps_name
= HeapAlloc(GetProcessHeap(), 0, strlen(ps_name
)+1);
145 strcpy(pdl
->ps_name
, ps_name
);
148 if(!is_room_for_font(physDev
))
149 PSDRV_EmptyDownloadList(physDev
, TRUE
);
151 if(physDev
->pi
->ppd
->TTRasterizer
== RO_Type42
) {
152 pdl
->typeinfo
.Type42
= T42_download_header(physDev
, potm
,
156 if(pdl
->typeinfo
.Type42
== NULL
) {
157 pdl
->typeinfo
.Type1
= T1_download_header(physDev
, potm
, ps_name
);
160 pdl
->next
= physDev
->downloaded_fonts
;
161 physDev
->downloaded_fonts
= pdl
;
162 physDev
->font
.fontinfo
.Download
= pdl
;
164 if(pdl
->type
== Type42
) {
165 char g_name
[MAX_G_NAME
+ 1];
166 get_glyph_name(physDev
->hdc
, 0, g_name
);
167 T42_download_glyph(physDev
, pdl
, 0, g_name
);
172 PSDRV_WriteSetFont(physDev
, ps_name
, physDev
->font
.size
,
173 physDev
->font
.escapement
);
175 HeapFree(GetProcessHeap(), 0, ps_name
);
176 HeapFree(GetProcessHeap(), 0, potm
);
180 void get_glyph_name(HDC hdc
, WORD index
, char *name
)
183 sprintf(name
, "g%04x", index
);
187 /****************************************************************************
188 * PSDRV_WriteDownloadGlyphShow
190 * Download and write out a number of glyphs
193 BOOL
PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE
*physDev
, WORD
*glyphs
,
197 char g_name
[MAX_G_NAME
+ 1];
198 assert(physDev
->font
.fontloc
== Download
);
200 switch(physDev
->font
.fontinfo
.Download
->type
) {
202 for(i
= 0; i
< count
; i
++) {
203 get_glyph_name(physDev
->hdc
, glyphs
[i
], g_name
);
204 T42_download_glyph(physDev
, physDev
->font
.fontinfo
.Download
,
206 PSDRV_WriteGlyphShow(physDev
, g_name
);
211 for(i
= 0; i
< count
; i
++) {
212 get_glyph_name(physDev
->hdc
, glyphs
[i
], g_name
);
213 T1_download_glyph(physDev
, physDev
->font
.fontinfo
.Download
,
215 PSDRV_WriteGlyphShow(physDev
, g_name
);
220 ERR("Type = %d\n", physDev
->font
.fontinfo
.Download
->type
);
226 /****************************************************************************
227 * PSDRV_EmptyDownloadList
229 * Clear the list of downloaded fonts
232 BOOL
PSDRV_EmptyDownloadList(PSDRV_PDEVICE
*physDev
, BOOL write_undef
)
235 char undef
[] = "/%s findfont 40 scalefont setfont /%s undefinefont\n";
236 char buf
[sizeof(undef
) + 200];
237 char *default_font
= physDev
->pi
->ppd
->DefaultFont
?
238 physDev
->pi
->ppd
->DefaultFont
: "Courier";
240 if(physDev
->font
.fontloc
== Download
) {
241 physDev
->font
.set
= FALSE
;
242 physDev
->font
.fontinfo
.Download
= NULL
;
245 pdl
= physDev
->downloaded_fonts
;
246 physDev
->downloaded_fonts
= NULL
;
249 sprintf(buf
, undef
, default_font
, pdl
->ps_name
);
250 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
255 T42_free(pdl
->typeinfo
.Type42
);
259 T1_free(pdl
->typeinfo
.Type1
);
263 ERR("Type = %d\n", pdl
->type
);
267 HeapFree(GetProcessHeap(), 0, pdl
->ps_name
);
270 HeapFree(GetProcessHeap(), 0, old
);