Release 20030709.
[wine/multimedia.git] / dlls / wineps / download.c
blob3d8f19bed7a9107c45fd2a40db8c2c86990c1717
1 /*
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
20 #include <string.h>
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <stdio.h>
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winspool.h"
30 #include "gdi.h"
31 #include "psdrv.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
37 /****************************************************************************
38 * get_download_name
40 static void get_download_name(PSDRV_PDEVICE *physDev, LPOUTLINETEXTMETRICA
41 potm, char **str)
43 int len;
44 char *p;
45 len = strlen((char*)potm + (ptrdiff_t)potm->otmpFullName) + 1;
46 *str = HeapAlloc(GetProcessHeap(),0,len);
47 strcpy(*str, (char*)potm + (ptrdiff_t)potm->otmpFullName);
49 p = *str;
50 while((p = strchr(p, ' ')))
51 *p = '_';
53 return;
56 /****************************************************************************
57 * is_font_downloaded
59 static DOWNLOAD *is_font_downloaded(PSDRV_PDEVICE *physDev, char *ps_name)
61 DOWNLOAD *pdl;
63 for(pdl = physDev->downloaded_fonts; pdl; pdl = pdl->next)
64 if(!strcmp(pdl->ps_name, ps_name))
65 break;
66 return pdl;
69 /****************************************************************************
70 * is_room_for_font
72 static BOOL is_room_for_font(PSDRV_PDEVICE *physDev)
74 DOWNLOAD *pdl;
75 int count = 0;
77 /* FIXME: should consider vm usage of each font and available printer memory.
78 For now we allow upto two fonts to be downloaded at a time */
79 for(pdl = physDev->downloaded_fonts; pdl; pdl = pdl->next)
80 count++;
82 if(count > 1)
83 return FALSE;
84 return TRUE;
87 /****************************************************************************
88 * PSDRV_SelectDownloadFont
90 * Set up physDev->font for a downloadable font
93 BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev)
95 char *ps_name;
96 LPOUTLINETEXTMETRICA potm;
97 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
99 potm = HeapAlloc(GetProcessHeap(), 0, len);
100 GetOutlineTextMetricsA(physDev->hdc, len, potm);
101 get_download_name(physDev, potm, &ps_name);
103 physDev->font.fontloc = Download;
104 physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name);
106 physDev->font.size = INTERNAL_YWSTODS(physDev->dc, /* ppem */
107 potm->otmTextMetrics.tmAscent +
108 potm->otmTextMetrics.tmDescent -
109 potm->otmTextMetrics.tmInternalLeading);
110 physDev->font.underlineThickness = potm->otmsUnderscoreSize;
111 physDev->font.underlinePosition = potm->otmsUnderscorePosition;
112 physDev->font.strikeoutThickness = potm->otmsStrikeoutSize;
113 physDev->font.strikeoutPosition = potm->otmsStrikeoutPosition;
115 HeapFree(GetProcessHeap(), 0, ps_name);
116 HeapFree(GetProcessHeap(), 0, potm);
117 return TRUE;
120 /****************************************************************************
121 * PSDRV_WriteSetDownloadFont
123 * Write setfont for download font.
126 BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev)
128 char *ps_name;
129 LPOUTLINETEXTMETRICA potm;
130 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
131 DOWNLOAD *pdl;
133 assert(physDev->font.fontloc == Download);
135 potm = HeapAlloc(GetProcessHeap(), 0, len);
136 GetOutlineTextMetricsA(physDev->hdc, len, potm);
138 get_download_name(physDev, potm, &ps_name);
140 if(physDev->font.fontinfo.Download == NULL) {
141 pdl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdl));
142 pdl->ps_name = HeapAlloc(GetProcessHeap(), 0, strlen(ps_name)+1);
143 strcpy(pdl->ps_name, ps_name);
144 pdl->next = NULL;
146 if(!is_room_for_font(physDev))
147 PSDRV_EmptyDownloadList(physDev, TRUE);
149 if(physDev->pi->ppd->TTRasterizer == RO_Type42) {
150 pdl->typeinfo.Type42 = T42_download_header(physDev, potm,
151 ps_name);
152 pdl->type = Type42;
154 if(pdl->typeinfo.Type42 == NULL) {
155 pdl->typeinfo.Type1 = T1_download_header(physDev, potm, ps_name);
156 pdl->type = Type1;
158 pdl->next = physDev->downloaded_fonts;
159 physDev->downloaded_fonts = pdl;
160 physDev->font.fontinfo.Download = pdl;
162 if(pdl->type == Type42) {
163 char g_name[MAX_G_NAME + 1];
164 get_glyph_name(physDev->hdc, 0, g_name);
165 T42_download_glyph(physDev, pdl, 0, g_name);
170 PSDRV_WriteSetFont(physDev, ps_name, physDev->font.size,
171 physDev->font.escapement);
173 HeapFree(GetProcessHeap(), 0, ps_name);
174 HeapFree(GetProcessHeap(), 0, potm);
175 return TRUE;
178 void get_glyph_name(HDC hdc, WORD index, char *name)
180 /* FIXME */
181 sprintf(name, "g%04x", index);
182 return;
185 /****************************************************************************
186 * PSDRV_WriteDownloadGlyphShow
188 * Download and write out a number of glyphs
191 BOOL PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE *physDev, WORD *glyphs,
192 UINT count)
194 UINT i;
195 char g_name[MAX_G_NAME + 1];
196 assert(physDev->font.fontloc == Download);
198 switch(physDev->font.fontinfo.Download->type) {
199 case Type42:
200 for(i = 0; i < count; i++) {
201 get_glyph_name(physDev->hdc, glyphs[i], g_name);
202 T42_download_glyph(physDev, physDev->font.fontinfo.Download,
203 glyphs[i], g_name);
204 PSDRV_WriteGlyphShow(physDev, g_name);
206 break;
208 case Type1:
209 for(i = 0; i < count; i++) {
210 get_glyph_name(physDev->hdc, glyphs[i], g_name);
211 T1_download_glyph(physDev, physDev->font.fontinfo.Download,
212 glyphs[i], g_name);
213 PSDRV_WriteGlyphShow(physDev, g_name);
215 break;
217 default:
218 ERR("Type = %d\n", physDev->font.fontinfo.Download->type);
219 assert(0);
221 return TRUE;
224 /****************************************************************************
225 * PSDRV_EmptyDownloadList
227 * Clear the list of downloaded fonts
230 BOOL PSDRV_EmptyDownloadList(PSDRV_PDEVICE *physDev, BOOL write_undef)
232 DOWNLOAD *pdl, *old;
233 char undef[] = "/%s findfont 40 scalefont setfont /%s undefinefont\n";
234 char buf[sizeof(undef) + 200];
235 char *default_font = physDev->pi->ppd->DefaultFont ?
236 physDev->pi->ppd->DefaultFont : "Courier";
238 if(physDev->font.fontloc == Download) {
239 physDev->font.set = FALSE;
240 physDev->font.fontinfo.Download = NULL;
243 pdl = physDev->downloaded_fonts;
244 physDev->downloaded_fonts = NULL;
245 while(pdl) {
246 if(write_undef) {
247 sprintf(buf, undef, default_font, pdl->ps_name);
248 PSDRV_WriteSpool(physDev, buf, strlen(buf));
251 switch(pdl->type) {
252 case Type42:
253 T42_free(pdl->typeinfo.Type42);
254 break;
256 case Type1:
257 T1_free(pdl->typeinfo.Type1);
258 break;
260 default:
261 ERR("Type = %d\n", pdl->type);
262 assert(0);
265 HeapFree(GetProcessHeap(), 0, pdl->ps_name);
266 old = pdl;
267 pdl = pdl->next;
268 HeapFree(GetProcessHeap(), 0, old);
270 return TRUE;