Use native msi until our own implementation works decently.
[wine/wine-kai.git] / dlls / wineps / download.c
blobc4ce963d2bb8b3859874f1eb339d8caeb4ad268b
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 <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winspool.h"
32 #include "gdi.h"
33 #include "psdrv.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
39 /****************************************************************************
40 * get_download_name
42 static void get_download_name(PSDRV_PDEVICE *physDev, LPOUTLINETEXTMETRICA
43 potm, char **str)
45 int len;
46 char *p;
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);
51 p = *str;
52 while((p = strchr(p, ' ')))
53 *p = '_';
55 return;
58 /****************************************************************************
59 * is_font_downloaded
61 static DOWNLOAD *is_font_downloaded(PSDRV_PDEVICE *physDev, char *ps_name)
63 DOWNLOAD *pdl;
65 for(pdl = physDev->downloaded_fonts; pdl; pdl = pdl->next)
66 if(!strcmp(pdl->ps_name, ps_name))
67 break;
68 return pdl;
71 /****************************************************************************
72 * is_room_for_font
74 static BOOL is_room_for_font(PSDRV_PDEVICE *physDev)
76 DOWNLOAD *pdl;
77 int count = 0;
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)
82 count++;
84 if(count > 1)
85 return FALSE;
86 return TRUE;
89 /****************************************************************************
90 * PSDRV_SelectDownloadFont
92 * Set up physDev->font for a downloadable font
95 BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev)
97 char *ps_name;
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);
119 return TRUE;
122 /****************************************************************************
123 * PSDRV_WriteSetDownloadFont
125 * Write setfont for download font.
128 BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev)
130 char *ps_name;
131 LPOUTLINETEXTMETRICA potm;
132 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
133 DOWNLOAD *pdl;
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);
146 pdl->next = NULL;
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,
153 ps_name);
154 pdl->type = Type42;
156 if(pdl->typeinfo.Type42 == NULL) {
157 pdl->typeinfo.Type1 = T1_download_header(physDev, potm, ps_name);
158 pdl->type = Type1;
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);
177 return TRUE;
180 void get_glyph_name(HDC hdc, WORD index, char *name)
182 /* FIXME */
183 sprintf(name, "g%04x", index);
184 return;
187 /****************************************************************************
188 * PSDRV_WriteDownloadGlyphShow
190 * Download and write out a number of glyphs
193 BOOL PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE *physDev, WORD *glyphs,
194 UINT count)
196 UINT i;
197 char g_name[MAX_G_NAME + 1];
198 assert(physDev->font.fontloc == Download);
200 switch(physDev->font.fontinfo.Download->type) {
201 case Type42:
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,
205 glyphs[i], g_name);
206 PSDRV_WriteGlyphShow(physDev, g_name);
208 break;
210 case Type1:
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,
214 glyphs[i], g_name);
215 PSDRV_WriteGlyphShow(physDev, g_name);
217 break;
219 default:
220 ERR("Type = %d\n", physDev->font.fontinfo.Download->type);
221 assert(0);
223 return TRUE;
226 /****************************************************************************
227 * PSDRV_EmptyDownloadList
229 * Clear the list of downloaded fonts
232 BOOL PSDRV_EmptyDownloadList(PSDRV_PDEVICE *physDev, BOOL write_undef)
234 DOWNLOAD *pdl, *old;
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;
247 while(pdl) {
248 if(write_undef) {
249 sprintf(buf, undef, default_font, pdl->ps_name);
250 PSDRV_WriteSpool(physDev, buf, strlen(buf));
253 switch(pdl->type) {
254 case Type42:
255 T42_free(pdl->typeinfo.Type42);
256 break;
258 case Type1:
259 T1_free(pdl->typeinfo.Type1);
260 break;
262 default:
263 ERR("Type = %d\n", pdl->type);
264 assert(0);
267 HeapFree(GetProcessHeap(), 0, pdl->ps_name);
268 old = pdl;
269 pdl = pdl->next;
270 HeapFree(GetProcessHeap(), 0, old);
272 return TRUE;