1 /*
2 *
3 * Copyright 2009 Austin English
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winreg.h"
26 #include "t2embapi.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(t2embed);
30
DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)31 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
32 {
33 switch (fdwReason)
34 {
35 case DLL_WINE_PREATTACH:
36 return FALSE; /* prefer native version */
37 case DLL_PROCESS_ATTACH:
38 DisableThreadLibraryCalls(hinstDLL);
39 break;
40 }
41
42 return TRUE;
43 }
44
TTLoadEmbeddedFont(HANDLE * phFontReference,ULONG ulFlags,ULONG * pulPrivStatus,ULONG ulPrivs,ULONG * pulStatus,READEMBEDPROC lpfnReadFromStream,LPVOID lpvReadStream,LPWSTR szWinFamilyName,LPSTR szMacFamilyName,TTLOADINFO * pTTLoadInfo)45 LONG WINAPI TTLoadEmbeddedFont(HANDLE *phFontReference, ULONG ulFlags,
46 ULONG *pulPrivStatus, ULONG ulPrivs,
47 ULONG *pulStatus, READEMBEDPROC lpfnReadFromStream,
48 LPVOID lpvReadStream, LPWSTR szWinFamilyName,
49 LPSTR szMacFamilyName, TTLOADINFO *pTTLoadInfo)
50 {
51 FIXME("(%p 0x%08x %p 0x%08x %p %p %p %s %s %p) stub\n", phFontReference,
52 ulFlags, pulPrivStatus, ulPrivs, pulStatus, lpfnReadFromStream,
53 lpvReadStream, debugstr_w(szWinFamilyName), szMacFamilyName,
54 pTTLoadInfo);
55
56 return E_API_NOTIMPL;
57 }
58
TTEmbedFont(HDC hDC,ULONG ulFlags,ULONG ulCharSet,ULONG * pulPrivStatus,ULONG * pulStatus,WRITEEMBEDPROC lpfnWriteToStream,LPVOID lpvWriteStream,USHORT * pusCharCodeSet,USHORT usCharCodeCount,USHORT usLanguage,TTEMBEDINFO * pTTEmbedInfo)59 LONG WINAPI TTEmbedFont(HDC hDC, ULONG ulFlags, ULONG ulCharSet, ULONG *pulPrivStatus,
60 ULONG *pulStatus, WRITEEMBEDPROC lpfnWriteToStream, LPVOID lpvWriteStream,
61 USHORT *pusCharCodeSet, USHORT usCharCodeCount, USHORT usLanguage,
62 TTEMBEDINFO *pTTEmbedInfo)
63 {
64 FIXME("(%p 0x%08x 0x%08x %p %p %p %p %p %u %u %p) stub\n", hDC,
65 ulFlags, ulCharSet, pulPrivStatus, pulStatus, lpfnWriteToStream,
66 lpvWriteStream, pusCharCodeSet, usCharCodeCount, usLanguage,
67 pTTEmbedInfo);
68
69 return E_API_NOTIMPL;
70 }
71
TTGetEmbeddingType(HDC hDC,ULONG * status)72 LONG WINAPI TTGetEmbeddingType(HDC hDC, ULONG *status)
73 {
74 OUTLINETEXTMETRICW otm;
75 WORD fsType;
76
77 TRACE("(%p %p)\n", hDC, status);
78
79 if (!hDC)
80 return E_HDCINVALID;
81
82 otm.otmSize = sizeof(otm);
83 if (!GetOutlineTextMetricsW(hDC, otm.otmSize, &otm))
84 return E_NOTATRUETYPEFONT;
85
86 if (!status)
87 return E_PERMISSIONSINVALID;
88
89 otm.otmfsType = (fsType = otm.otmfsType) & 0xf;
90 if (otm.otmfsType == LICENSE_INSTALLABLE)
91 *status = EMBED_INSTALLABLE;
92 else if (otm.otmfsType & LICENSE_EDITABLE)
93 *status = EMBED_EDITABLE;
94 else if (otm.otmfsType & LICENSE_PREVIEWPRINT)
95 *status = EMBED_PREVIEWPRINT;
96 else if (otm.otmfsType & LICENSE_NOEMBEDDING)
97 *status = EMBED_NOEMBEDDING;
98 else
99 {
100 WARN("unrecognized flags, %#x\n", otm.otmfsType);
101 *status = EMBED_INSTALLABLE;
102 }
103
104 TRACE("fsType 0x%04x, status %u\n", fsType, *status);
105 return E_NONE;
106 }
107
TTIsEmbeddingEnabledForFacename(LPCSTR facename,BOOL * enabled)108 LONG WINAPI TTIsEmbeddingEnabledForFacename(LPCSTR facename, BOOL *enabled)
109 {
110 static const WCHAR exclusionlistW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
111 'S','h','a','r','e','d',' ','T','o','o','l','s','\\','t','2','e','m','b','e','d',0};
112 DWORD index;
113 HKEY hkey;
114 LONG ret;
115
116 TRACE("(%s %p)\n", debugstr_a(facename), enabled);
117
118 if (!facename)
119 return E_FACENAMEINVALID;
120
121 if (!enabled)
122 return E_PBENABLEDINVALID;
123
124 *enabled = TRUE;
125 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, exclusionlistW, 0, GENERIC_READ, &hkey))
126 goto out;
127
128 *enabled = TRUE;
129 ret = ERROR_SUCCESS;
130 index = 0;
131 while (ret != ERROR_NO_MORE_ITEMS)
132 {
133 DWORD name_len, value_len, value, type;
134 CHAR name[LF_FACESIZE];
135
136 name_len = ARRAY_SIZE(name);
137 value_len = sizeof(value);
138 ret = RegEnumValueA(hkey, index++, name, &name_len, NULL, &type, (BYTE*)&value, &value_len);
139 if (ret || type != REG_DWORD)
140 continue;
141
142 if (!lstrcmpiA(name, facename))
143 {
144 *enabled = !!value;
145 break;
146 }
147 }
148 RegCloseKey(hkey);
149
150 out:
151 TRACE("embedding %s for %s\n", *enabled ? "enabled" : "disabled", debugstr_a(facename));
152 return E_NONE;
153 }
154
TTIsEmbeddingEnabled(HDC hDC,BOOL * enabled)155 LONG WINAPI TTIsEmbeddingEnabled(HDC hDC, BOOL *enabled)
156 {
157 OUTLINETEXTMETRICA *otm;
158 LONG ret;
159 UINT len;
160
161 TRACE("(%p %p)\n", hDC, enabled);
162
163 if (!hDC)
164 return E_HDCINVALID;
165
166 len = GetOutlineTextMetricsA(hDC, 0, NULL);
167 if (!len)
168 return E_ERRORACCESSINGFACENAME;
169
170 otm = HeapAlloc(GetProcessHeap(), 0, len);
171 if (!otm)
172 return E_NOFREEMEMORY;
173
174 GetOutlineTextMetricsA(hDC, len, otm);
175 ret = TTIsEmbeddingEnabledForFacename((LPCSTR)otm + (ULONG_PTR)otm->otmpFaceName, enabled);
176 HeapFree(GetProcessHeap(), 0, otm);
177 return ret;
178 }
179
TTDeleteEmbeddedFont(HANDLE hFontReference,ULONG flags,ULONG * status)180 LONG WINAPI TTDeleteEmbeddedFont(HANDLE hFontReference, ULONG flags, ULONG *status)
181 {
182 FIXME("(%p 0x%08x %p) stub\n", hFontReference, flags, status);
183 return E_API_NOTIMPL;
184 }
185