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
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
37 /****************************************************************************
40 static void get_download_name(PSDRV_PDEVICE
*physDev
, LPOUTLINETEXTMETRICA
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
);
50 while((p
= strchr(p
, ' ')))
56 /****************************************************************************
59 static DOWNLOAD
*is_font_downloaded(PSDRV_PDEVICE
*physDev
, char *ps_name
)
63 for(pdl
= physDev
->downloaded_fonts
; pdl
; pdl
= pdl
->next
)
64 if(!strcmp(pdl
->ps_name
, ps_name
))
69 /****************************************************************************
72 static BOOL
is_room_for_font(PSDRV_PDEVICE
*physDev
)
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
)
87 /****************************************************************************
88 * PSDRV_SelectDownloadFont
90 * Set up physDev->font for a downloadable font
93 BOOL
PSDRV_SelectDownloadFont(PSDRV_PDEVICE
*physDev
)
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
);
120 /****************************************************************************
121 * PSDRV_WriteSetDownloadFont
123 * Write setfont for download font.
126 BOOL
PSDRV_WriteSetDownloadFont(PSDRV_PDEVICE
*physDev
)
129 LPOUTLINETEXTMETRICA potm
;
130 DWORD len
= GetOutlineTextMetricsA(physDev
->hdc
, 0, NULL
);
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
);
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
,
154 if(pdl
->typeinfo
.Type42
== NULL
) {
155 pdl
->typeinfo
.Type1
= T1_download_header(physDev
, potm
, ps_name
);
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
);
178 void get_glyph_name(HDC hdc
, WORD index
, char *name
)
181 sprintf(name
, "g%04x", index
);
185 /****************************************************************************
186 * PSDRV_WriteDownloadGlyphShow
188 * Download and write out a number of glyphs
191 BOOL
PSDRV_WriteDownloadGlyphShow(PSDRV_PDEVICE
*physDev
, WORD
*glyphs
,
195 char g_name
[MAX_G_NAME
+ 1];
196 assert(physDev
->font
.fontloc
== Download
);
198 switch(physDev
->font
.fontinfo
.Download
->type
) {
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
,
204 PSDRV_WriteGlyphShow(physDev
, g_name
);
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
,
213 PSDRV_WriteGlyphShow(physDev
, g_name
);
218 ERR("Type = %d\n", physDev
->font
.fontinfo
.Download
->type
);
224 /****************************************************************************
225 * PSDRV_EmptyDownloadList
227 * Clear the list of downloaded fonts
230 BOOL
PSDRV_EmptyDownloadList(PSDRV_PDEVICE
*physDev
, BOOL write_undef
)
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
;
247 sprintf(buf
, undef
, default_font
, pdl
->ps_name
);
248 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
253 T42_free(pdl
->typeinfo
.Type42
);
257 T1_free(pdl
->typeinfo
.Type1
);
261 ERR("Type = %d\n", pdl
->type
);
265 HeapFree(GetProcessHeap(), 0, pdl
->ps_name
);
268 HeapFree(GetProcessHeap(), 0, old
);