Pass -l's that are not .dll's or .a's to the linker.
[wine] / dlls / wineps / download.c
1 /*
2  *      PostScript driver downloadable font functions
3  *
4  *      Copyright 2002  Huw D M Davies for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
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"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
31
32
33 /****************************************************************************
34  *  get_download_name
35  */
36 static void get_download_name(PSDRV_PDEVICE *physDev, LPOUTLINETEXTMETRICA
37                               potm, char **str)
38 {
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);
44
45     p = *str;
46     while((p = strchr(p, ' ')))
47         *p = '_';
48
49     return;
50 }
51
52 /****************************************************************************
53  *  is_font_downloaded
54  */
55 static DOWNLOAD *is_font_downloaded(PSDRV_PDEVICE *physDev, char *ps_name)
56 {
57     DOWNLOAD *pdl;
58
59     for(pdl = physDev->downloaded_fonts; pdl; pdl = pdl->next)
60         if(!strcmp(pdl->ps_name, ps_name))
61             break;
62     return pdl;
63 }
64
65 /****************************************************************************
66  *  PSDRV_SelectDownloadFont
67  *
68  *  Set up physDev->font for a downloadable font
69  *
70  */
71 BOOL PSDRV_SelectDownloadFont(PSDRV_PDEVICE *physDev)
72 {
73     char *ps_name;
74     LPOUTLINETEXTMETRICA potm;
75     DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
76
77     potm = HeapAlloc(GetProcessHeap(), 0, len);
78     GetOutlineTextMetricsA(physDev->hdc, len, potm);
79     get_download_name(physDev, potm, &ps_name);
80
81     physDev->font.fontloc = Download;
82     physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name);
83
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;
92
93     HeapFree(GetProcessHeap(), 0, ps_name);
94     HeapFree(GetProcessHeap(), 0, potm);
95     return TRUE;
96 }
97
98 /****************************************************************************
99  *  PSDRV_WriteSetDownloadFont
100  *
101  *  Write setfont for download font.
102  *
103  */
104 BOOL PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE *physDev)
105 {
106     char *ps_name;
107     LPOUTLINETEXTMETRICA potm;
108     DWORD len = GetOutlineTextMetricsA(physDev->hdc, 0, NULL);
109     DOWNLOAD *pdl;
110
111     assert(physDev->font.fontloc == Download);
112
113     potm = HeapAlloc(GetProcessHeap(), 0, len);
114     GetOutlineTextMetricsA(physDev->hdc, len, potm);
115
116     get_download_name(physDev, potm, &ps_name);
117
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;
123
124         if(physDev->pi->ppd->TTRasterizer == RO_Type42) {
125             pdl->typeinfo.Type42 = T42_download_header(physDev, potm,
126                                                        ps_name);
127             pdl->type = Type42;
128         }
129         if(pdl->typeinfo.Type42 == NULL) {
130             pdl->typeinfo.Type1 = T1_download_header(physDev, potm, ps_name);
131             pdl->type = Type1;
132         }
133         pdl->next = physDev->downloaded_fonts;
134         physDev->downloaded_fonts = pdl;
135         physDev->font.fontinfo.Download = pdl;
136     }
137
138
139     PSDRV_WriteSetFont(physDev, ps_name, physDev->font.size,
140                        physDev->font.escapement);
141
142     HeapFree(GetProcessHeap(), 0, ps_name);
143     HeapFree(GetProcessHeap(), 0, potm);
144     return TRUE;
145 }
146
147 void get_glyph_name(HDC hdc, WORD index, char *name)
148 {
149   /* FIXME */
150     sprintf(name, "g%04x", index);
151     return;
152 }
153
154 /****************************************************************************
155  *  PSDRV_WriteDownloadGlyphShow
156  *
157  *  Download and write out a number of glyphs
158  *
159  */
160 BOOL PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE *physDev, WORD *glyphs,
161                                   UINT count)
162 {
163     UINT i;
164     char g_name[MAX_G_NAME + 1];
165     assert(physDev->font.fontloc == Download);
166
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);
174     }
175     break;
176
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);
183     }
184     break;
185
186     default:
187         ERR("Type = %d\n", physDev->font.fontinfo.Download->type);
188         assert(0);
189     }
190     return TRUE;
191 }
192
193 /****************************************************************************
194  *  PSDRV_EmptyDownloadList
195  *
196  *  Clear the list of downloaded fonts
197  *
198  */
199 BOOL PSDRV_EmptyDownloadList(PSDRV_PDEVICE *physDev)
200 {
201     DOWNLOAD *pdl, *old;
202     if(physDev->font.fontloc == Download) {
203         physDev->font.set = FALSE;
204         physDev->font.fontinfo.Download = NULL;
205     }
206
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;
214
215         case Type1:
216             T1_free(pdl->typeinfo.Type1);
217             break;
218
219         default:
220             ERR("Type = %d\n", pdl->type);
221             assert(0);
222         }
223
224         HeapFree(GetProcessHeap(), 0, pdl->ps_name);
225         old = pdl;
226         pdl = pdl->next;
227         HeapFree(GetProcessHeap(), 0, old);
228     }
229     return TRUE;
230 }