MagickCore  6.9.12-67
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
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 "magick/studio.h"
44 #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
45 #include "magick/cache.h"
46 #include "magick/colorspace.h"
47 #include "magick/colorspace-private.h"
48 #include "magick/draw.h"
49 #include "magick/exception.h"
50 #include "magick/exception-private.h"
51 #include "magick/image-private.h"
52 #include "magick/locale-private.h"
53 #include "magick/memory_.h"
54 #include "magick/monitor.h"
55 #include "magick/monitor-private.h"
56 #include "magick/nt-base.h"
57 #include "magick/nt-base-private.h"
58 #include "magick/nt-feature.h"
59 #include "magick/pixel-accessor.h"
60 #include "magick/quantum.h"
61 #include "magick/string_.h"
62 #include "magick/token.h"
63 #include "magick/splay-tree.h"
64 #include "magick/utility.h"
65 #if defined(__CYGWIN__)
66 #define WIN32_LEAN_AND_MEAN
67 #define VC_EXTRALEAN
68 #include <windows.h>
69 #endif
70 
71 /*
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % %
74 % %
75 % %
76 % I s M a g i c k C o n f l i c t %
77 % %
78 % %
79 % %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %
82 % IsMagickConflict() returns true if the image format conflicts with a logical
83 % drive (.e.g. X:).
84 %
85 % The format of the IsMagickConflict method is:
86 %
87 % MagickBooleanType IsMagickConflict(const char *magick)
88 %
89 % A description of each parameter follows:
90 %
91 % o magick: Specifies the image format.
92 %
93 */
94 MagickExport MagickBooleanType NTIsMagickConflict(const char *magick)
95 {
96  MagickBooleanType
97  status;
98 
99  assert(magick != (char *) NULL);
100  if (strlen(magick) > 1)
101  return(MagickFalse);
102  status=(GetLogicalDrives() & (1 <<
103  ((LocaleToUppercase((int) (*magick)))-'A'))) != 0 ? MagickTrue : MagickFalse;
104  return(status);
105 }
106 
107 /*
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % %
110 % %
111 % %
112 % N T A c q u i r e T y p e C a c h e %
113 % %
114 % %
115 % %
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %
118 % NTAcquireTypeCache() loads a Windows TrueType fonts.
119 %
120 % The format of the NTAcquireTypeCache method is:
121 %
122 % MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache)
123 %
124 % A description of each parameter follows:
125 %
126 % o type_cache: A linked list of fonts.
127 %
128 */
129 MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache,
130  ExceptionInfo *exception)
131 {
132  HKEY
133  reg_key = (HKEY) INVALID_HANDLE_VALUE;
134 
135  LONG
136  res;
137 
138  int
139  list_entries = 0;
140 
141  char
142  buffer[MaxTextExtent],
143  system_root[MaxTextExtent],
144  font_root[MaxTextExtent];
145 
146  DWORD
147  type,
148  system_root_length;
149 
150  MagickBooleanType
151  status;
152 
153  /*
154  Try to find the right Windows*\CurrentVersion key, the SystemRoot and
155  then the Fonts key
156  */
157  res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
158  "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &reg_key);
159  if (res == ERROR_SUCCESS) {
160  system_root_length=sizeof(system_root)-1;
161  res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
162  (BYTE*) system_root, &system_root_length);
163  }
164  if (res != ERROR_SUCCESS) {
165  res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
166  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &reg_key);
167  if (res == ERROR_SUCCESS) {
168  system_root_length=sizeof(system_root)-1;
169  res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
170  (BYTE*)system_root, &system_root_length);
171  }
172  }
173  if (res == ERROR_SUCCESS)
174  res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, &reg_key);
175  if (res != ERROR_SUCCESS)
176  return(MagickFalse);
177  *font_root='\0';
178  (void) CopyMagickString(buffer,system_root,MaxTextExtent);
179  (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MaxTextExtent);
180  if (IsPathAccessible(buffer) != MagickFalse)
181  {
182  (void) CopyMagickString(font_root,system_root,MaxTextExtent);
183  (void) ConcatenateMagickString(font_root,"\\fonts\\",MaxTextExtent);
184  }
185  else
186  {
187  (void) CopyMagickString(font_root,system_root,MaxTextExtent);
188  (void) ConcatenateMagickString(font_root,"\\",MaxTextExtent);
189  }
190 
191  {
192  TypeInfo
193  *type_info;
194 
195  DWORD
196  registry_index = 0,
197  type,
198  value_data_size,
199  value_name_length;
200 
201  char
202  value_data[MaxTextExtent],
203  value_name[MaxTextExtent];
204 
205  res = ERROR_SUCCESS;
206 
207  while (res != ERROR_NO_MORE_ITEMS)
208  {
209  char
210  *family_extent,
211  token[MaxTextExtent],
212  *pos,
213  *q;
214 
215  value_name_length = sizeof(value_name) - 1;
216  value_data_size = sizeof(value_data) - 1;
217  res=RegEnumValueA(reg_key,registry_index,value_name,&value_name_length,
218  0,&type,(BYTE *) value_data,&value_data_size);
219  registry_index++;
220  if (res != ERROR_SUCCESS)
221  continue;
222  if ((pos=strstr(value_name," (TrueType)")) == (char*) NULL)
223  continue;
224  *pos='\0'; /* Remove (TrueType) from string */
225  type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
226  if (type_info == (TypeInfo *) NULL)
227  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
228  (void) memset(type_info,0,sizeof(TypeInfo));
229  type_info->path=ConstantString("Windows Fonts");
230  type_info->signature=MagickCoreSignature;
231  (void) CopyMagickString(buffer,value_name,MaxTextExtent); /* name */
232  for (pos=buffer; *pos != 0; pos++)
233  if (*pos == ' ')
234  *pos='-';
235  type_info->name=ConstantString(buffer);
236  type_info->description=ConstantString(value_name); /* fullname */
237  type_info->format=ConstantString("truetype"); /* format */
238  if (strchr(value_data,'\\') != (char *) NULL) /* glyphs */
239  (void) CopyMagickString(buffer,value_data,MaxTextExtent);
240  else
241  {
242  (void) CopyMagickString(buffer,font_root,MaxTextExtent);
243  (void) ConcatenateMagickString(buffer,value_data,MaxTextExtent);
244  }
245  LocaleLower(buffer);
246  type_info->glyphs=ConstantString(buffer);
247  type_info->stretch=NormalStretch;
248  type_info->style=NormalStyle;
249  type_info->weight=400;
250  /*
251  Some fonts are known to require special encodings.
252  */
253  if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) ||
254  (LocaleCompare(type_info->name, "Wingdings") == 0 ) ||
255  (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) ||
256  (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) )
257  type_info->encoding=ConstantString("AppleRoman");
258  family_extent=value_name;
259  for (q=value_name; *q != '\0'; )
260  {
261  (void) GetNextToken(q,(const char **) &q,MaxTextExtent,token);
262  if (*token == '\0')
263  break;
264 
265  if (LocaleCompare(token,"Italic") == 0)
266  {
267  type_info->style=ItalicStyle;
268  }
269 
270  else if (LocaleCompare(token,"Oblique") == 0)
271  {
272  type_info->style=ObliqueStyle;
273  }
274 
275  else if (LocaleCompare(token,"Bold") == 0)
276  {
277  type_info->weight=700;
278  }
279 
280  else if (LocaleCompare(token,"Thin") == 0)
281  {
282  type_info->weight=100;
283  }
284 
285  else if ( (LocaleCompare(token,"ExtraLight") == 0) ||
286  (LocaleCompare(token,"UltraLight") == 0) )
287  {
288  type_info->weight=200;
289  }
290 
291  else if (LocaleCompare(token,"Light") == 0)
292  {
293  type_info->weight=300;
294  }
295 
296  else if ( (LocaleCompare(token,"Normal") == 0) ||
297  (LocaleCompare(token,"Regular") == 0) )
298  {
299  type_info->weight=400;
300  }
301 
302  else if (LocaleCompare(token,"Medium") == 0)
303  {
304  type_info->weight=500;
305  }
306 
307  else if ( (LocaleCompare(token,"SemiBold") == 0) ||
308  (LocaleCompare(token,"DemiBold") == 0) )
309  {
310  type_info->weight=600;
311  }
312 
313  else if ( (LocaleCompare(token,"ExtraBold") == 0) ||
314  (LocaleCompare(token,"UltraBold") == 0) )
315  {
316  type_info->weight=800;
317  }
318 
319  else if ( (LocaleCompare(token,"Heavy") == 0) ||
320  (LocaleCompare(token,"Black") == 0) )
321  {
322  type_info->weight=900;
323  }
324 
325  else if (LocaleCompare(token,"Condensed") == 0)
326  {
327  type_info->stretch = CondensedStretch;
328  }
329 
330  else if (LocaleCompare(token,"Expanded") == 0)
331  {
332  type_info->stretch = ExpandedStretch;
333  }
334 
335  else if (LocaleCompare(token,"ExtraCondensed") == 0)
336  {
337  type_info->stretch = ExtraCondensedStretch;
338  }
339 
340  else if (LocaleCompare(token,"ExtraExpanded") == 0)
341  {
342  type_info->stretch = ExtraExpandedStretch;
343  }
344 
345  else if (LocaleCompare(token,"SemiCondensed") == 0)
346  {
347  type_info->stretch = SemiCondensedStretch;
348  }
349 
350  else if (LocaleCompare(token,"SemiExpanded") == 0)
351  {
352  type_info->stretch = SemiExpandedStretch;
353  }
354 
355  else if (LocaleCompare(token,"UltraCondensed") == 0)
356  {
357  type_info->stretch = UltraCondensedStretch;
358  }
359 
360  else if (LocaleCompare(token,"UltraExpanded") == 0)
361  {
362  type_info->stretch = UltraExpandedStretch;
363  }
364 
365  else
366  {
367  family_extent=q;
368  }
369  }
370 
371  (void) CopyMagickString(buffer,value_name,family_extent-value_name+1);
372  StripString(buffer);
373  type_info->family=ConstantString(buffer);
374 
375  list_entries++;
376  status=AddValueToSplayTree(type_cache,type_info->name,type_info);
377  if (status == MagickFalse)
378  (void) ThrowMagickException(exception,GetMagickModule(),
379  ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
380  }
381  }
382  RegCloseKey(reg_key);
383  return(MagickTrue);
384 }
385 
386 #endif
Definition: type.h:50