MagickCore 7.1.2
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
nt-feature.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% %
7% N N TTTTT %
8% NN N T %
9% N N N T %
10% N NN T %
11% N N T %
12% %
13% %
14% Windows NT Feature Methods for MagickCore %
15% %
16% Software Design %
17% Cristy %
18% December 1996 %
19% %
20% %
21% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
22% dedicated to making software imaging solutions freely available. %
23% %
24% You may not use this file except in compliance with the License. You may %
25% obtain a copy of the License at %
26% %
27% https://imagemagick.org/script/license.php %
28% %
29% Unless required by applicable law or agreed to in writing, software %
30% distributed under the License is distributed on an "AS IS" BASIS, %
31% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32% See the License for the specific language governing permissions and %
33% limitations under the License. %
34% %
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include "MagickCore/studio.h"
44#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
45#include "MagickCore/cache.h"
46#include "MagickCore/colorspace.h"
47#include "MagickCore/colorspace-private.h"
48#include "MagickCore/draw.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/image-private.h"
52#include "MagickCore/locale-private.h"
53#include "MagickCore/memory_.h"
54#include "MagickCore/memory-private.h"
55#include "MagickCore/monitor.h"
56#include "MagickCore/monitor-private.h"
57#include "MagickCore/nt-base.h"
58#include "MagickCore/nt-base-private.h"
59#include "MagickCore/nt-feature.h"
60#include "MagickCore/pixel-accessor.h"
61#include "MagickCore/quantum.h"
62#include "MagickCore/string_.h"
63#include "MagickCore/token.h"
64#include "MagickCore/splay-tree.h"
65#include "MagickCore/utility.h"
66#if defined(__CYGWIN__)
67#define WIN32_LEAN_AND_MEAN
68#define VC_EXTRALEAN
69#include <windows.h>
70#endif
71
72/*
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74% %
75% %
76% %
77% I s M a g i c k C o n f l i c t %
78% %
79% %
80% %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82%
83% IsMagickConflict() returns true if the image format conflicts with a logical
84% drive (.e.g. X:).
85%
86% The format of the IsMagickConflict method is:
87%
88% MagickBooleanType IsMagickConflict(const char *magick)
89%
90% A description of each parameter follows:
91%
92% o magick: Specifies the image format.
93%
94*/
95MagickExport MagickBooleanType NTIsMagickConflict(const char *magick)
96{
97 MagickBooleanType
98 status;
99
100 assert(magick != (char *) NULL);
101 if (strlen(magick) > 1)
102 return(MagickFalse);
103 status=(GetLogicalDrives() & (1 << ((LocaleToUppercase((int)
104 (*magick)))-'A'))) != 0 ? MagickTrue : MagickFalse;
105 return(status);
106}
107
108/*
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110% %
111% %
112% %
113% N T A c q u i r e T y p e C a c h e %
114% %
115% %
116% %
117%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118%
119% NTAcquireTypeCache() loads a Windows TrueType fonts.
120%
121% The format of the NTAcquireTypeCache method is:
122%
123% MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache)
124%
125% A description of each parameter follows:
126%
127% o type_cache: A linked list of fonts.
128%
129*/
130MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache,
131 ExceptionInfo *exception)
132{
133 HKEY
134 reg_key;
135
136 LONG
137 res;
138
139 char
140 buffer[MagickPathExtent],
141 font_root[MagickPathExtent];
142
143 DWORD
144 type,
145 length;
146
147 MagickBooleanType
148 status;
149
150 /*
151 Try to find the right Windows*\CurrentVersion key, the SystemRoot and
152 then the Fonts key
153 */
154 reg_key=(HKEY) INVALID_HANDLE_VALUE;
155 res=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
156 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",0,KEY_READ,&reg_key);
157 length=sizeof(font_root)-1;
158 if (res == ERROR_SUCCESS)
159 res=RegQueryValueExA(reg_key,"SystemRoot",NULL,&type,(BYTE*) font_root,
160 &length);
161 if (res != ERROR_SUCCESS)
162 {
163 res=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
164 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion",0,KEY_READ,&reg_key);
165 if (res == ERROR_SUCCESS)
166 res=RegQueryValueExA(reg_key,"SystemRoot",NULL,&type,(BYTE*) font_root,
167 &length);
168 }
169 if (res == ERROR_SUCCESS)
170 res=RegOpenKeyExA(reg_key,"Fonts",0,KEY_READ,&reg_key);
171 if (res != ERROR_SUCCESS)
172 return(MagickFalse);
173 (void) ConcatenateMagickString(font_root,"\\fonts\\arial.ttf",
174 MagickPathExtent);
175 if (IsPathAccessible(font_root) != MagickFalse)
176 {
177 font_root[length-1]=0;
178 (void) ConcatenateMagickString(font_root,"\\fonts\\",MagickPathExtent);
179 }
180 else
181 {
182 font_root[length-1]=0;
183 (void) ConcatenateMagickString(font_root,"\\",MagickPathExtent);
184 }
185
186 {
187 TypeInfo
188 *type_info;
189
190 DWORD
191 registry_index;
192
193 char
194 utf8[MagickPathExtent];
195
196 wchar_t
197 wide_name[MagickPathExtent],
198 wide_value[MagickPathExtent];
199
200 registry_index=0;
201 res=ERROR_SUCCESS;
202 while (res != ERROR_NO_MORE_ITEMS)
203 {
204 char
205 *family_extent,
206 *pos,
207 *q;
208
209 DWORD
210 name_length,
211 value_length;
212
213 name_length=MagickPathExtent-1;
214 value_length=MagickPathExtent-1;
215 res=RegEnumValueW(reg_key,registry_index,(wchar_t *) wide_name,
216 &name_length,0,&type,(BYTE *) wide_value,&value_length);
217 registry_index++;
218 if (res != ERROR_SUCCESS)
219 continue;
220 WideCharToMultiByte(CP_UTF8,0,wide_name,-1,utf8,sizeof(utf8),NULL,
221 NULL);
222 if ((pos=strstr(utf8," (TrueType)")) == (char*) NULL)
223 continue;
224 *pos='\0'; /* Remove (TrueType) from string */
225 type_info=(TypeInfo *) AcquireCriticalMemory(sizeof(*type_info));
226 (void) memset(type_info,0,sizeof(TypeInfo));
227 type_info->path=ConstantString("Windows Fonts");
228 type_info->signature=MagickCoreSignature;
229 (void) CopyMagickString(buffer,utf8,MagickPathExtent);
230 for (pos=buffer; *pos != 0; pos++)
231 if (*pos == ' ')
232 *pos = '-';
233 type_info->name=ConstantString(buffer);
234 type_info->description=ConstantString(utf8);
235 type_info->format=ConstantString("truetype");
236 type_info->stretch=NormalStretch;
237 type_info->style=NormalStyle;
238 type_info->weight=400;
239 /* Some fonts are known to require special encodings */
240 if ((LocaleCompare(type_info->name, "Symbol") == 0) ||
241 (LocaleCompare(type_info->name, "Wingdings") == 0) ||
242 (LocaleCompare(type_info->name, "Wingdings-2") == 0) ||
243 (LocaleCompare(type_info->name, "Wingdings-3") == 0))
244 type_info->encoding=ConstantString("AppleRoman");
245 family_extent=utf8;
246 for (q=utf8; *q != '\0'; )
247 {
248 char
249 token[MagickPathExtent];
250
251 (void) GetNextToken(q,(const char **) &q,MagickPathExtent,token);
252 if (*token == '\0')
253 break;
254 if (LocaleCompare(token,"Italic") == 0)
255 type_info->style=ItalicStyle;
256 else if (LocaleCompare(token,"Oblique") == 0)
257 type_info->style=ObliqueStyle;
258 else if (LocaleCompare(token,"Bold") == 0)
259 type_info->weight=700;
260 else if (LocaleCompare(token,"Thin") == 0)
261 type_info->weight=100;
262 else if ((LocaleCompare(token,"ExtraLight") == 0) ||
263 (LocaleCompare(token,"UltraLight") == 0))
264 type_info->weight=200;
265 else if (LocaleCompare(token,"Light") == 0)
266 type_info->weight=300;
267 else if ((LocaleCompare(token,"Normal") == 0) ||
268 (LocaleCompare(token,"Regular") == 0))
269 type_info->weight=400;
270 else if (LocaleCompare(token,"Medium") == 0)
271 type_info->weight=500;
272 else if ((LocaleCompare(token,"SemiBold") == 0) ||
273 (LocaleCompare(token,"DemiBold") == 0))
274 type_info->weight=600;
275 else if ((LocaleCompare(token,"ExtraBold") == 0) ||
276 (LocaleCompare(token,"UltraBold") == 0))
277 type_info->weight=800;
278 else if ((LocaleCompare(token,"Heavy") == 0) ||
279 (LocaleCompare(token,"Black") == 0))
280 type_info->weight=900;
281 else if (LocaleCompare(token,"Condensed") == 0)
282 type_info->stretch = CondensedStretch;
283 else if (LocaleCompare(token,"Expanded") == 0)
284 type_info->stretch = ExpandedStretch;
285 else if (LocaleCompare(token,"ExtraCondensed") == 0)
286 type_info->stretch = ExtraCondensedStretch;
287 else if (LocaleCompare(token,"ExtraExpanded") == 0)
288 type_info->stretch = ExtraExpandedStretch;
289 else if (LocaleCompare(token,"SemiCondensed") == 0)
290 type_info->stretch = SemiCondensedStretch;
291 else if (LocaleCompare(token,"SemiExpanded") == 0)
292 type_info->stretch = SemiExpandedStretch;
293 else if (LocaleCompare(token,"UltraCondensed") == 0)
294 type_info->stretch = UltraCondensedStretch;
295 else if (LocaleCompare(token,"UltraExpanded") == 0)
296 type_info->stretch = UltraExpandedStretch;
297 else
298 family_extent=q;
299 }
300 (void) CopyMagickString(buffer,utf8,family_extent-utf8+1);
301 (void) StripMagickString(buffer);
302 type_info->family=ConstantString(buffer);
303 WideCharToMultiByte(CP_UTF8,0,wide_value,-1,utf8,sizeof(utf8),NULL,
304 NULL);
305 if (strchr(utf8,'\\') != (char *) NULL)
306 (void) CopyMagickString(buffer,utf8,MagickPathExtent);
307 else
308 {
309 (void) CopyMagickString(buffer,font_root,MagickPathExtent);
310 (void) ConcatenateMagickString(buffer,utf8,MagickPathExtent);
311 }
312 LocaleLower(buffer);
313 type_info->glyphs=ConstantString(buffer);
314 status=AddValueToSplayTree(type_cache,type_info->name,type_info);
315 if (status == MagickFalse)
316 (void) ThrowMagickException(exception,GetMagickModule(),
317 ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
318 }
319 }
320 RegCloseKey(reg_key);
321 return(MagickTrue);
322}
323
324#endif