Removed obsolete INT_Int31Handler.
[wine/multimedia.git] / dlls / wineps / download.c
blob9c012603a5ad55c4c5f4042fe85f5e0c2a3ccff0
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>
24 #include "winspool.h"
25 #include "gdi.h"
26 #include "psdrv.h"
27 #include "wine/debug.h"
28 #include "winerror.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
33 /****************************************************************************
34 * get_download_name
36 static void get_download_name(PSDRV_PDEVICE *physDev, LPOUTLINETEXTMETRICA
37 potm, char **str)
39 int len;
40 char *p;
41 len = strlen((char*)potm + (ptrdiff_t)potm->otmpFullName) + 1;
42 *str = HeapAlloc(GetProcessHeap(),0,len);
43 strcpy(*str, (char*)potm + (ptrdiff_t)potm->otmpFullName);
45 p = *str;
46 while((p = strchr(p, ' ')))
47 *p = '_';
49 return;
52 /****************************************************************************
53 * is_font_downloaded
55 static DOWNLOAD *is_font_downloaded(PSDRV_PDEVICE *physDev, char *ps_name)
57 DOWNLOAD *pdl;
59 for(pdl = physDev->downloaded_fonts; pdl; pdl = pdl->next)
60 if(!strcmp(pdl->ps_name, ps_name))
61 break;
62 return pdl;
65 /****************************************************************************
66 * PSDRV_SelectDownloadFont
68 * Set up physDev->font for a downloadable font
71 BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev)
73 char *ps_name;
74 LPOUTLINETEXTMETRICA potm;
75 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
77 potm = HeapAlloc(GetProcessHeap(), 0, len);
78 GetOutlineTextMetricsA(physDev->hdc, len, potm);
79 get_download_name(physDev, potm, &ps_name);
81 physDev->font.fontloc = Download;
82 physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name);
84 physDev->font.size = INTERNAL_YWSTODS(physDev->dc, /* ppem */
85 potm->otmTextMetrics.tmAscent +
86 potm->otmTextMetrics.tmDescent -
87 potm->otmTextMetrics.tmInternalLeading);
88 physDev->font.underlineThickness = potm->otmsUnderscoreSize;
89 physDev->font.underlinePosition = potm->otmsUnderscorePosition;
90 physDev->font.strikeoutThickness = potm->otmsStrikeoutSize;
91 physDev->font.strikeoutPosition = potm->otmsStrikeoutPosition;
93 HeapFree(GetProcessHeap(), 0, ps_name);
94 HeapFree(GetProcessHeap(), 0, potm);
95 return TRUE;
98 /****************************************************************************
99 * PSDRV_WriteSetDownloadFont
101 * Write setfont for download font.
104 BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev)
106 char *ps_name;
107 LPOUTLINETEXTMETRICA potm;
108 DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
109 DOWNLOAD *pdl;
111 assert(physDev->font.fontloc == Download);
113 potm = HeapAlloc(GetProcessHeap(), 0, len);
114 GetOutlineTextMetricsA(physDev->hdc, len, potm);
116 get_download_name(physDev, potm, &ps_name);
118 if(physDev->font.fontinfo.Download == NULL) {
119 pdl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdl));
120 pdl->ps_name = HeapAlloc(GetProcessHeap(), 0, strlen(ps_name)+1);
121 strcpy(pdl->ps_name, ps_name);
122 pdl->next = NULL;
124 if(physDev->pi->ppd->TTRasterizer == RO_Type42) {
125 pdl->typeinfo.Type42 = T42_download_header(physDev, potm,
126 ps_name);
127 pdl->type = Type42;
129 if(pdl->typeinfo.Type42 == NULL) {
130 pdl->typeinfo.Type1 = T1_download_header(physDev, potm, ps_name);
131 pdl->type = Type1;
133 pdl->next = physDev->downloaded_fonts;
134 physDev->downloaded_fonts = pdl;
135 physDev->font.fontinfo.Download = pdl;
139 PSDRV_WriteSetFont(physDev, ps_name, physDev->font.size,
140 physDev->font.escapement);
142 HeapFree(GetProcessHeap(), 0, ps_name);
143 HeapFree(GetProcessHeap(), 0, potm);
144 return TRUE;
147 void get_glyph_name(HDC hdc, WORD index, char *name)
149 /* FIXME */
150 sprintf(name, "g%04x", index);
151 return;
154 /****************************************************************************
155 * PSDRV_WriteDownloadGlyphShow
157 * Download and write out a number of glyphs
160 BOOL PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE *physDev, WORD *glyphs,
161 UINT count)
163 UINT i;
164 char g_name[MAX_G_NAME + 1];
165 assert(physDev->font.fontloc == Download);
167 switch(physDev->font.fontinfo.Download->type) {
168 case Type42:
169 for(i = 0; i < count; i++) {
170 get_glyph_name(physDev->hdc, glyphs[i], g_name);
171 T42_download_glyph(physDev, physDev->font.fontinfo.Download,
172 glyphs[i], g_name);
173 PSDRV_WriteGlyphShow(physDev, g_name);
175 break;
177 case Type1:
178 for(i = 0; i < count; i++) {
179 get_glyph_name(physDev->hdc, glyphs[i], g_name);
180 T1_download_glyph(physDev, physDev->font.fontinfo.Download,
181 glyphs[i], g_name);
182 PSDRV_WriteGlyphShow(physDev, g_name);
184 break;
186 default:
187 ERR("Type = %d\n", physDev->font.fontinfo.Download->type);
188 assert(0);
190 return TRUE;
193 /****************************************************************************
194 * PSDRV_EmptyDownloadList
196 * Clear the list of downloaded fonts
199 BOOL PSDRV_EmptyDownloadList(PSDRV_PDEVICE *physDev)
201 DOWNLOAD *pdl, *old;
202 if(physDev->font.fontloc == Download) {
203 physDev->font.set = FALSE;
204 physDev->font.fontinfo.Download = NULL;
207 pdl = physDev->downloaded_fonts;
208 physDev->downloaded_fonts = NULL;
209 while(pdl) {
210 switch(pdl->type) {
211 case Type42:
212 T42_free(pdl->typeinfo.Type42);
213 break;
215 case Type1:
216 T1_free(pdl->typeinfo.Type1);
217 break;
219 default:
220 ERR("Type = %d\n", pdl->type);
221 assert(0);
224 HeapFree(GetProcessHeap(), 0, pdl->ps_name);
225 old = pdl;
226 pdl = pdl->next;
227 HeapFree(GetProcessHeap(), 0, old);
229 return TRUE;