MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
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 */
95 MagickExport 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 */
130 MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache,
131  ExceptionInfo *exception)
132 {
133  HKEY
134  reg_key;
135 
136  LONG
137  res;
138 
139  int
140  list_entries;
141 
142  char
143  buffer[MagickPathExtent],
144  font_root[MagickPathExtent];
145 
146  DWORD
147  type,
148  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  list_entries=0;
158  reg_key=(HKEY) INVALID_HANDLE_VALUE;
159  res=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
160  "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",0,KEY_READ,&reg_key);
161  length=sizeof(font_root)-1;
162  if (res == ERROR_SUCCESS)
163  res=RegQueryValueExA(reg_key,"SystemRoot",NULL,&type,(BYTE*) font_root,
164  &length);
165  if (res != ERROR_SUCCESS)
166  {
167  res=RegOpenKeyExA(HKEY_LOCAL_MACHINE,
168  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion",0,KEY_READ,&reg_key);
169  if (res == ERROR_SUCCESS)
170  res=RegQueryValueExA(reg_key,"SystemRoot",NULL,&type,(BYTE*) font_root,
171  &length);
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  (void) ConcatenateMagickString(font_root,"\\fonts\\arial.ttf",
178  MagickPathExtent);
179  if (IsPathAccessible(font_root) != MagickFalse)
180  {
181  font_root[length-1]=0;
182  (void) ConcatenateMagickString(font_root,"\\fonts\\",MagickPathExtent);
183  }
184  else
185  {
186  font_root[length-1]=0;
187  (void) ConcatenateMagickString(font_root,"\\",MagickPathExtent);
188  }
189 
190  {
191  TypeInfo
192  *type_info;
193 
194  DWORD
195  registry_index;
196 
197  char
198  utf8[MagickPathExtent];
199 
200  wchar_t
201  wide_name[MagickPathExtent],
202  wide_value[MagickPathExtent];
203 
204  registry_index=0;
205  res=ERROR_SUCCESS;
206  while (res != ERROR_NO_MORE_ITEMS)
207  {
208  char
209  *family_extent,
210  *pos,
211  *q;
212 
213  DWORD
214  name_length,
215  value_length;
216 
217  name_length=MagickPathExtent-1;
218  value_length=MagickPathExtent-1;
219  res=RegEnumValueW(reg_key,registry_index,(wchar_t *) wide_name,
220  &name_length,0,&type,(BYTE *) wide_value,&value_length);
221  registry_index++;
222  if (res != ERROR_SUCCESS)
223  continue;
224  WideCharToMultiByte(CP_UTF8,0,wide_name,-1,utf8,sizeof(utf8),NULL,
225  NULL);
226  if ((pos=strstr(utf8," (TrueType)")) == (char*) NULL)
227  continue;
228  *pos='\0'; /* Remove (TrueType) from string */
229  type_info=(TypeInfo *) AcquireCriticalMemory(sizeof(*type_info));
230  (void) memset(type_info,0,sizeof(TypeInfo));
231  type_info->path=ConstantString("Windows Fonts");
232  type_info->signature=MagickCoreSignature;
233  (void) CopyMagickString(buffer,utf8,MagickPathExtent);
234  for (pos=buffer; *pos != 0; pos++)
235  if (*pos == ' ')
236  *pos = '-';
237  type_info->name=ConstantString(buffer);
238  type_info->description=ConstantString(utf8);
239  type_info->format=ConstantString("truetype");
240  type_info->stretch=NormalStretch;
241  type_info->style=NormalStyle;
242  type_info->weight=400;
243  /* Some fonts are known to require special encodings */
244  if ((LocaleCompare(type_info->name, "Symbol") == 0) ||
245  (LocaleCompare(type_info->name, "Wingdings") == 0) ||
246  (LocaleCompare(type_info->name, "Wingdings-2") == 0) ||
247  (LocaleCompare(type_info->name, "Wingdings-3") == 0))
248  type_info->encoding=ConstantString("AppleRoman");
249  family_extent=utf8;
250  for (q=utf8; *q != '\0'; )
251  {
252  char
253  token[MagickPathExtent];
254 
255  (void) GetNextToken(q,(const char **) &q,MagickPathExtent,token);
256  if (*token == '\0')
257  break;
258  if (LocaleCompare(token,"Italic") == 0)
259  type_info->style=ItalicStyle;
260  else if (LocaleCompare(token,"Oblique") == 0)
261  type_info->style=ObliqueStyle;
262  else if (LocaleCompare(token,"Bold") == 0)
263  type_info->weight=700;
264  else if (LocaleCompare(token,"Thin") == 0)
265  type_info->weight=100;
266  else if ((LocaleCompare(token,"ExtraLight") == 0) ||
267  (LocaleCompare(token,"UltraLight") == 0))
268  type_info->weight=200;
269  else if (LocaleCompare(token,"Light") == 0)
270  type_info->weight=300;
271  else if ((LocaleCompare(token,"Normal") == 0) ||
272  (LocaleCompare(token,"Regular") == 0))
273  type_info->weight=400;
274  else if (LocaleCompare(token,"Medium") == 0)
275  type_info->weight=500;
276  else if ((LocaleCompare(token,"SemiBold") == 0) ||
277  (LocaleCompare(token,"DemiBold") == 0))
278  type_info->weight=600;
279  else if ((LocaleCompare(token,"ExtraBold") == 0) ||
280  (LocaleCompare(token,"UltraBold") == 0))
281  type_info->weight=800;
282  else if ((LocaleCompare(token,"Heavy") == 0) ||
283  (LocaleCompare(token,"Black") == 0))
284  type_info->weight=900;
285  else if (LocaleCompare(token,"Condensed") == 0)
286  type_info->stretch = CondensedStretch;
287  else if (LocaleCompare(token,"Expanded") == 0)
288  type_info->stretch = ExpandedStretch;
289  else if (LocaleCompare(token,"ExtraCondensed") == 0)
290  type_info->stretch = ExtraCondensedStretch;
291  else if (LocaleCompare(token,"ExtraExpanded") == 0)
292  type_info->stretch = ExtraExpandedStretch;
293  else if (LocaleCompare(token,"SemiCondensed") == 0)
294  type_info->stretch = SemiCondensedStretch;
295  else if (LocaleCompare(token,"SemiExpanded") == 0)
296  type_info->stretch = SemiExpandedStretch;
297  else if (LocaleCompare(token,"UltraCondensed") == 0)
298  type_info->stretch = UltraCondensedStretch;
299  else if (LocaleCompare(token,"UltraExpanded") == 0)
300  type_info->stretch = UltraExpandedStretch;
301  else
302  family_extent=q;
303  }
304  (void) CopyMagickString(buffer,utf8,family_extent-utf8+1);
305  (void) StripMagickString(buffer);
306  type_info->family=ConstantString(buffer);
307  WideCharToMultiByte(CP_UTF8,0,wide_value,-1,utf8,sizeof(utf8),NULL,
308  NULL);
309  if (strchr(utf8,'\\') != (char *) NULL)
310  (void) CopyMagickString(buffer,utf8,MagickPathExtent);
311  else
312  {
313  (void) CopyMagickString(buffer,font_root,MagickPathExtent);
314  (void) ConcatenateMagickString(buffer,utf8,MagickPathExtent);
315  }
316  LocaleLower(buffer);
317  type_info->glyphs=ConstantString(buffer);
318  list_entries++;
319  status=AddValueToSplayTree(type_cache,type_info->name,type_info);
320  if (status == MagickFalse)
321  (void) ThrowMagickException(exception,GetMagickModule(),
322  ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
323  }
324  }
325  RegCloseKey(reg_key);
326  return(MagickTrue);
327 }
328 ␌
329 #endif
Definition: type.h:51