Remove extra #include directives from winspool.h.
[wine/multimedia.git] / dlls / wineps / download.c
blob749387d9db5f4182a98a1c74dc03a10ce5f54bd3
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 * PSDRV_SelectDownloadFont
72 * Set up physDev->font for a downloadable font
75 BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev)
77 char *ps_name;
78 LPOUTLINETEXTMETRICA potm;
79 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
81 potm = HeapAlloc(GetProcessHeap(), 0, len);
82 GetOutlineTextMetricsA(physDev->hdc, len, potm);
83 get_download_name(physDev, potm, &ps_name);
85 physDev->font.fontloc = Download;
86 physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name);
88 physDev->font.size = INTERNAL_YWSTODS(physDev->dc, /* ppem */
89 potm->otmTextMetrics.tmAscent +
90 potm->otmTextMetrics.tmDescent -
91 potm->otmTextMetrics.tmInternalLeading);
92 physDev->font.underlineThickness = potm->otmsUnderscoreSize;
93 physDev->font.underlinePosition = potm->otmsUnderscorePosition;
94 physDev->font.strikeoutThickness = potm->otmsStrikeoutSize;
95 physDev->font.strikeoutPosition = potm->otmsStrikeoutPosition;
97 HeapFree(GetProcessHeap(), 0, ps_name);
98 HeapFree(GetProcessHeap(), 0, potm);
99 return TRUE;
102 /****************************************************************************
103 * PSDRV_WriteSetDownloadFont
105 * Write setfont for download font.
108 BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev)
110 char *ps_name;
111 LPOUTLINETEXTMETRICA potm;
112 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
113 DOWNLOAD *pdl;
115 assert(physDev->font.fontloc == Download);
117 potm = HeapAlloc(GetProcessHeap(), 0, len);
118 GetOutlineTextMetricsA(physDev->hdc, len, potm);
120 get_download_name(physDev, potm, &ps_name);
122 if(physDev->font.fontinfo.Download == NULL) {
123 pdl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdl));
124 pdl->ps_name = HeapAlloc(GetProcessHeap(), 0, strlen(ps_name)+1);
125 strcpy(pdl->ps_name, ps_name);
126 pdl->next = NULL;
128 if(physDev->pi->ppd->TTRasterizer == RO_Type42) {
129 pdl->typeinfo.Type42 = T42_download_header(physDev, potm,
130 ps_name);
131 pdl->type = Type42;
133 if(pdl->typeinfo.Type42 == NULL) {
134 pdl->typeinfo.Type1 = T1_download_header(physDev, potm, ps_name);
135 pdl->type = Type1;
137 pdl->next = physDev->downloaded_fonts;
138 physDev->downloaded_fonts = pdl;
139 physDev->font.fontinfo.Download = pdl;
143 PSDRV_WriteSetFont(physDev, ps_name, physDev->font.size,
144 physDev->font.escapement);
146 HeapFree(GetProcessHeap(), 0, ps_name);
147 HeapFree(GetProcessHeap(), 0, potm);
148 return TRUE;
151 void get_glyph_name(HDC hdc, WORD index, char *name)
153 /* FIXME */
154 sprintf(name, "g%04x", index);
155 return;
158 /****************************************************************************
159 * PSDRV_WriteDownloadGlyphShow
161 * Download and write out a number of glyphs
164 BOOL PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE *physDev, WORD *glyphs,
165 UINT count)
167 UINT i;
168 char g_name[MAX_G_NAME + 1];
169 assert(physDev->font.fontloc == Download);
171 switch(physDev->font.fontinfo.Download->type) {
172 case Type42:
173 for(i = 0; i < count; i++) {
174 get_glyph_name(physDev->hdc, glyphs[i], g_name);
175 T42_download_glyph(physDev, physDev->font.fontinfo.Download,
176 glyphs[i], g_name);
177 PSDRV_WriteGlyphShow(physDev, g_name);
179 break;
181 case Type1:
182 for(i = 0; i < count; i++) {
183 get_glyph_name(physDev->hdc, glyphs[i], g_name);
184 T1_download_glyph(physDev, physDev->font.fontinfo.Download,
185 glyphs[i], g_name);
186 PSDRV_WriteGlyphShow(physDev, g_name);
188 break;
190 default:
191 ERR("Type = %d\n", physDev->font.fontinfo.Download->type);
192 assert(0);
194 return TRUE;
197 /****************************************************************************
198 * PSDRV_EmptyDownloadList
200 * Clear the list of downloaded fonts
203 BOOL PSDRV_EmptyDownloadList(PSDRV_PDEVICE *physDev)
205 DOWNLOAD *pdl, *old;
206 if(physDev->font.fontloc == Download) {
207 physDev->font.set = FALSE;
208 physDev->font.fontinfo.Download = NULL;
211 pdl = physDev->downloaded_fonts;
212 physDev->downloaded_fonts = NULL;
213 while(pdl) {
214 switch(pdl->type) {
215 case Type42:
216 T42_free(pdl->typeinfo.Type42);
217 break;
219 case Type1:
220 T1_free(pdl->typeinfo.Type1);
221 break;
223 default:
224 ERR("Type = %d\n", pdl->type);
225 assert(0);
228 HeapFree(GetProcessHeap(), 0, pdl->ps_name);
229 old = pdl;
230 pdl = pdl->next;
231 HeapFree(GetProcessHeap(), 0, old);
233 return TRUE;