MagickCore 7.1.1
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
type.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% TTTTT Y Y PPPP EEEEE %
7% T Y Y P P E %
8% T Y PPPP EEE %
9% T Y P E %
10% T Y P EEEEE %
11% %
12% %
13% MagickCore Image Type Methods %
14% %
15% Software Design %
16% Cristy %
17% May 2001 %
18% %
19% %
20% Copyright @ 2001 ImageMagick Studio LLC, a non-profit organization %
21% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% https://imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/client.h"
45#include "MagickCore/configure.h"
46#include "MagickCore/draw.h"
47#include "MagickCore/exception.h"
48#include "MagickCore/exception-private.h"
49#include "MagickCore/image-private.h"
50#include "MagickCore/linked-list.h"
51#include "MagickCore/log.h"
52#include "MagickCore/memory_.h"
53#include "MagickCore/memory-private.h"
54#include "MagickCore/nt-feature.h"
55#include "MagickCore/nt-base-private.h"
56#include "MagickCore/option.h"
57#include "MagickCore/semaphore.h"
58#include "MagickCore/splay-tree.h"
59#include "MagickCore/string_.h"
60#include "MagickCore/string-private.h"
61#include "MagickCore/type.h"
62#include "MagickCore/type-private.h"
63#include "MagickCore/token.h"
64#include "MagickCore/utility.h"
65#include "MagickCore/utility-private.h"
66#include "MagickCore/xml-tree.h"
67#if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
68# include "fontconfig/fontconfig.h"
69#if (FC_VERSION < 20209)
70#undef FC_WEIGHT_LIGHT
71#define FC_WIDTH "width" /* Int */
72#define FC_WIDTH_ULTRACONDENSED 50
73#define FC_WIDTH_EXTRACONDENSED 63
74#define FC_WIDTH_CONDENSED 75
75#define FC_WIDTH_SEMICONDENSED 87
76#define FC_WIDTH_NORMAL 100
77#define FC_WIDTH_SEMIEXPANDED 113
78#define FC_WIDTH_EXPANDED 125
79#define FC_WIDTH_EXTRAEXPANDED 150
80#define FC_WIDTH_ULTRAEXPANDED 200
81
82#define FC_WEIGHT_THIN 0
83#define FC_WEIGHT_EXTRALIGHT 40
84#define FC_WEIGHT_ULTRALIGHT FC_WEIGHT_EXTRALIGHT
85#define FC_WEIGHT_LIGHT 50
86#define FC_WEIGHT_BOOK 75
87#define FC_WEIGHT_REGULAR 80
88#define FC_WEIGHT_NORMAL FC_WEIGHT_REGULAR
89#define FC_WEIGHT_MEDIUM 100
90#define FC_WEIGHT_DEMIBOLD 180
91#define FC_WEIGHT_SEMIBOLD FC_WEIGHT_DEMIBOLD
92#define FC_WEIGHT_BOLD 200
93#define FC_WEIGHT_EXTRABOLD 205
94#define FC_WEIGHT_ULTRABOLD FC_WEIGHT_EXTRABOLD
95#define FC_WEIGHT_BLACK 210
96#define FC_WEIGHT_HEAVY FC_WEIGHT_BLACK
97#endif
98#endif
99#if defined(MAGICKCORE_WINDOWS_SUPPORT)
100# include "MagickCore/nt-feature.h"
101#endif
102
103/*
104 Define declarations.
105*/
106#define MagickTypeFilename "type.xml"
107
108/*
109 Declare type map.
110*/
111static const char
112 TypeMap[] =
113 "<?xml version=\"1.0\"?>"
114 "<typemap>"
115 " <type stealth=\"True\" name=\"fixed\" family=\"helvetica\"/>"
116 " <type stealth=\"True\" name=\"helvetica\" family=\"helvetica\"/>"
117 "</typemap>";
118
119/*
120 Static declarations.
121*/
122static SemaphoreInfo
123 *type_semaphore = (SemaphoreInfo *) NULL;
124
125static SplayTreeInfo
126 *type_cache = (SplayTreeInfo *) NULL;
127
128/*
129 Forward declarations.
130*/
131static MagickBooleanType
132 IsTypeTreeInstantiated(ExceptionInfo *),
133 LoadTypeCache(SplayTreeInfo *,const char *,const char *,const size_t,
134 ExceptionInfo *);
135
136/*
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138% %
139% %
140% %
141% A c q u i r e T y p e S p l a y T r e e %
142% %
143% %
144% %
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146%
147% AcquireTypeCache() caches one or more type configuration files which
148% provides a mapping between type attributes and a type name.
149%
150% The format of the AcquireTypeCache method is:
151%
152% SplayTreeInfo *AcquireTypeCache(const char *filename,
153% ExceptionInfo *exception)
154%
155% A description of each parameter follows:
156%
157% o filename: the font file name.
158%
159% o exception: return any errors or warnings in this structure.
160%
161*/
162
163static void *DestroyTypeNode(void *type_info)
164{
166 *p;
167
168 p=(TypeInfo *) type_info;
169 if (p->path != (char *) NULL)
170 p->path=DestroyString(p->path);
171 if (p->name != (char *) NULL)
172 p->name=DestroyString(p->name);
173 if (p->description != (char *) NULL)
174 p->description=DestroyString(p->description);
175 if (p->family != (char *) NULL)
176 p->family=DestroyString(p->family);
177 if (p->encoding != (char *) NULL)
178 p->encoding=DestroyString(p->encoding);
179 if (p->foundry != (char *) NULL)
180 p->foundry=DestroyString(p->foundry);
181 if (p->format != (char *) NULL)
182 p->format=DestroyString(p->format);
183 if (p->metrics != (char *) NULL)
184 p->metrics=DestroyString(p->metrics);
185 if (p->glyphs != (char *) NULL)
186 p->glyphs=DestroyString(p->glyphs);
187 return(RelinquishMagickMemory(p));
188}
189
190static SplayTreeInfo *AcquireTypeCache(const char *filename,
191 ExceptionInfo *exception)
192{
194 *cache;
195
196 cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
197 DestroyTypeNode);
198 if (cache == (SplayTreeInfo *) NULL)
199 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
200#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
201 {
202 char
203 *font_path,
204 path[MagickPathExtent];
205
206 const StringInfo
207 *option;
208
210 *options;
211
212 *path='\0';
213 options=GetConfigureOptions(filename,exception);
214 option=(const StringInfo *) GetNextValueInLinkedList(options);
215 while (option != (const StringInfo *) NULL)
216 {
217 (void) CopyMagickString(path,GetStringInfoPath(option),MagickPathExtent);
218 (void) LoadTypeCache(cache,(const char *) GetStringInfoDatum(option),
219 GetStringInfoPath(option),0,exception);
220 option=(const StringInfo *) GetNextValueInLinkedList(options);
221 }
222 options=DestroyConfigureOptions(options);
223 font_path=GetEnvironmentValue("MAGICK_FONT_PATH");
224 if (font_path != (char *) NULL)
225 {
226 char
227 *xml;
228
229 /*
230 Search MAGICK_FONT_PATH.
231 */
232 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",font_path,
233 DirectorySeparator,filename);
234 xml=FileToString(path,~0UL,exception);
235 if (xml != (void *) NULL)
236 {
237 (void) LoadTypeCache(cache,xml,path,0,exception);
238 xml=DestroyString(xml);
239 }
240 font_path=DestroyString(font_path);
241 }
242 }
243#else
244 magick_unreferenced(filename);
245#endif
246 if (GetNumberOfNodesInSplayTree(cache) == 0)
247 (void) LoadTypeCache(cache,TypeMap,"built-in",0,exception);
248 return(cache);
249}
250
251/*
252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253% %
254% %
255% %
256+ G e t T y p e I n f o %
257% %
258% %
259% %
260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261%
262% GetTypeInfo searches the type list for the specified name and if found
263% returns attributes for that type.
264%
265% The format of the GetTypeInfo method is:
266%
267% const TypeInfo *GetTypeInfo(const char *name,ExceptionInfo *exception)
268%
269% A description of each parameter follows:
270%
271% o name: the type name.
272%
273% o exception: return any errors or warnings in this structure.
274%
275*/
276MagickExport const TypeInfo *GetTypeInfo(const char *name,
277 ExceptionInfo *exception)
278{
279 assert(exception != (ExceptionInfo *) NULL);
280 if (IsTypeTreeInstantiated(exception) == MagickFalse)
281 return((const TypeInfo *) NULL);
282 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
283 return((const TypeInfo *) GetRootValueFromSplayTree(type_cache));
284 return((const TypeInfo *) GetValueFromSplayTree(type_cache,name));
285}
286
287/*
288%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289% %
290% %
291% %
292+ G e t T y p e I n f o B y F a m i l y %
293% %
294% %
295% %
296%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297%
298% GetTypeInfoByFamily() searches the type list for the specified family and if
299% found returns attributes for that type.
300%
301% Type substitution and scoring algorithm contributed by Bob Friesenhahn.
302%
303% The format of the GetTypeInfoByFamily method is:
304%
305% const TypeInfo *GetTypeInfoByFamily(const char *family,
306% const StyleType style,const StretchType stretch,
307% const size_t weight,ExceptionInfo *exception)
308%
309% A description of each parameter follows:
310%
311% o family: the type family.
312%
313% o style: the type style.
314%
315% o stretch: the type stretch.
316%
317% o weight: the type weight.
318%
319% o exception: return any errors or warnings in this structure.
320%
321*/
322MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
323 const StyleType style,const StretchType stretch,const size_t weight,
324 ExceptionInfo *exception)
325{
326 typedef struct _Fontmap
327 {
328 const char
329 name[17],
330 substitute[10];
331 } Fontmap;
332
333 const TypeInfo
334 *p,
335 *type_info;
336
337 size_t
338 font_weight,
339 max_score,
340 score;
341
342 ssize_t
343 i,
344 range;
345
346 static const Fontmap
347 fontmap[] =
348 {
349 { "fixed", "courier" },
350 { "modern","courier" },
351 { "monotype corsiva", "courier" },
352 { "news gothic", "helvetica" },
353 { "system", "courier" },
354 { "terminal", "courier" },
355 { "wingdings", "symbol" }
356 };
357
358 /*
359 Check for an exact type match.
360 */
361 (void) GetTypeInfo("*",exception);
362 if (type_cache == (SplayTreeInfo *) NULL)
363 return((TypeInfo *) NULL);
364 font_weight=(size_t) (weight == 0 ? 400 : weight);
365 LockSemaphoreInfo(type_semaphore);
366 ResetSplayTreeIterator(type_cache);
367 type_info=(const TypeInfo *) NULL;
368 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
369 while (p != (const TypeInfo *) NULL)
370 {
371 if (p->family == (char *) NULL)
372 {
373 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
374 continue;
375 }
376 if (family == (const char *) NULL)
377 {
378 if ((LocaleCompare(p->family,"arial") != 0) &&
379 (LocaleCompare(p->family,"helvetica") != 0))
380 {
381 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
382 continue;
383 }
384 }
385 else
386 if (LocaleCompare(p->family,family) != 0)
387 {
388 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
389 continue;
390 }
391 if ((style != UndefinedStyle) && (style != AnyStyle) && (p->style != style))
392 {
393 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
394 continue;
395 }
396 if ((stretch != UndefinedStretch) && (stretch != AnyStretch) &&
397 (p->stretch != stretch))
398 {
399 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
400 continue;
401 }
402 if (p->weight != font_weight)
403 {
404 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
405 continue;
406 }
407 type_info=p;
408 break;
409 }
410 UnlockSemaphoreInfo(type_semaphore);
411 if (type_info != (const TypeInfo *) NULL)
412 return(type_info);
413 /*
414 Check for types in the same family.
415 */
416 max_score=0;
417 LockSemaphoreInfo(type_semaphore);
418 ResetSplayTreeIterator(type_cache);
419 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
420 while (p != (const TypeInfo *) NULL)
421 {
422 if (p->family == (char *) NULL)
423 {
424 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
425 continue;
426 }
427 if (family == (const char *) NULL)
428 {
429 if ((LocaleCompare(p->family,"arial") != 0) &&
430 (LocaleCompare(p->family,"helvetica") != 0))
431 {
432 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
433 continue;
434 }
435 }
436 else
437 if (LocaleCompare(p->family,family) != 0)
438 {
439 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
440 continue;
441 }
442 score=0;
443 if ((style == UndefinedStyle) || (style == AnyStyle) || (p->style == style))
444 score+=32;
445 else
446 if (((style == ItalicStyle) || (style == ObliqueStyle)) &&
447 ((p->style == ItalicStyle) || (p->style == ObliqueStyle)))
448 score+=25;
449 score+=(size_t) ((16L*(800L-((ssize_t) MagickMax(MagickMin(font_weight,900),
450 p->weight)-(ssize_t) MagickMin(MagickMin(font_weight,900),p->weight))))/
451 800L);
452 if ((stretch == UndefinedStretch) || (stretch == AnyStretch))
453 score+=8;
454 else
455 {
456 range=(ssize_t) UltraExpandedStretch-(ssize_t) NormalStretch;
457 score+=(size_t) ((ssize_t) (8L*(range-((ssize_t) MagickMax(stretch,
458 p->stretch)-(ssize_t) MagickMin(stretch,p->stretch))))/range);
459 }
460 if (score > max_score)
461 {
462 max_score=score;
463 type_info=p;
464 }
465 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
466 }
467 UnlockSemaphoreInfo(type_semaphore);
468 if (type_info != (const TypeInfo *) NULL)
469 return(type_info);
470 /*
471 Check for table-based substitution match.
472 */
473 for (i=0; i < (ssize_t) (sizeof(fontmap)/sizeof(fontmap[0])); i++)
474 {
475 if (family == (const char *) NULL)
476 {
477 if ((LocaleCompare(fontmap[i].name,"arial") != 0) &&
478 (LocaleCompare(fontmap[i].name,"helvetica") != 0))
479 continue;
480 }
481 else
482 if (LocaleCompare(fontmap[i].name,family) != 0)
483 continue;
484 type_info=GetTypeInfoByFamily(fontmap[i].substitute,style,stretch,weight,
485 exception);
486 break;
487 }
488 if (type_info != (const TypeInfo *) NULL)
489 {
490 (void) ThrowMagickException(exception,GetMagickModule(),TypeWarning,
491 "FontSubstitutionRequired","`%s'",type_info->family);
492 return(type_info);
493 }
494 if (family != (const char *) NULL)
495 type_info=GetTypeInfoByFamily((const char *) NULL,style,stretch,weight,
496 exception);
497 return(type_info);
498}
499
500/*
501%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
502% %
503% %
504% %
505% G e t T y p e I n f o L i s t %
506% %
507% %
508% %
509%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
510%
511% GetTypeInfoList() returns any fonts that match the specified pattern.
512%
513% The format of the GetTypeInfoList function is:
514%
515% const TypeInfo **GetTypeInfoList(const char *pattern,
516% size_t *number_fonts,ExceptionInfo *exception)
517%
518% A description of each parameter follows:
519%
520% o pattern: Specifies a pointer to a text string containing a pattern.
521%
522% o number_fonts: This integer returns the number of types in the list.
523%
524% o exception: return any errors or warnings in this structure.
525%
526*/
527
528#if defined(__cplusplus) || defined(c_plusplus)
529extern "C" {
530#endif
531
532static int TypeInfoCompare(const void *x,const void *y)
533{
534 const TypeInfo
535 **p,
536 **q;
537
538 p=(const TypeInfo **) x,
539 q=(const TypeInfo **) y;
540 if (LocaleCompare((*p)->path,(*q)->path) == 0)
541 return(LocaleCompare((*p)->name,(*q)->name));
542 return(LocaleCompare((*p)->path,(*q)->path));
543}
544
545#if defined(__cplusplus) || defined(c_plusplus)
546}
547#endif
548
549MagickExport const TypeInfo **GetTypeInfoList(const char *pattern,
550 size_t *number_fonts,ExceptionInfo *exception)
551{
552 const TypeInfo
553 **fonts;
554
555 const TypeInfo
556 *p;
557
558 ssize_t
559 i;
560
561 /*
562 Allocate type list.
563 */
564 assert(pattern != (char *) NULL);
565 assert(number_fonts != (size_t *) NULL);
566 if (IsEventLogging() != MagickFalse)
567 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
568 *number_fonts=0;
569 p=GetTypeInfo("*",exception);
570 if (p == (const TypeInfo *) NULL)
571 return((const TypeInfo **) NULL);
572 fonts=(const TypeInfo **) AcquireQuantumMemory((size_t)
573 GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts));
574 if (fonts == (const TypeInfo **) NULL)
575 return((const TypeInfo **) NULL);
576 /*
577 Generate type list.
578 */
579 LockSemaphoreInfo(type_semaphore);
580 ResetSplayTreeIterator(type_cache);
581 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
582 for (i=0; p != (const TypeInfo *) NULL; )
583 {
584 if ((p->stealth == MagickFalse) &&
585 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
586 fonts[i++]=p;
587 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
588 }
589 UnlockSemaphoreInfo(type_semaphore);
590 qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeInfoCompare);
591 fonts[i]=(TypeInfo *) NULL;
592 *number_fonts=(size_t) i;
593 return(fonts);
594}
595
596/*
597%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598% %
599% %
600% %
601% G e t T y p e L i s t %
602% %
603% %
604% %
605%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606%
607% GetTypeList() returns any fonts that match the specified pattern.
608%
609% The format of the GetTypeList function is:
610%
611% char **GetTypeList(const char *pattern,size_t *number_fonts,
612% ExceptionInfo *exception)
613%
614% A description of each parameter follows:
615%
616% o pattern: Specifies a pointer to a text string containing a pattern.
617%
618% o number_fonts: This integer returns the number of fonts in the list.
619%
620% o exception: return any errors or warnings in this structure.
621%
622*/
623
624#if defined(__cplusplus) || defined(c_plusplus)
625extern "C" {
626#endif
627
628static int TypeCompare(const void *x,const void *y)
629{
630 const char
631 **p,
632 **q;
633
634 p=(const char **) x;
635 q=(const char **) y;
636 return(LocaleCompare(*p,*q));
637}
638
639#if defined(__cplusplus) || defined(c_plusplus)
640}
641#endif
642
643MagickExport char **GetTypeList(const char *pattern,size_t *number_fonts,
644 ExceptionInfo *exception)
645{
646 char
647 **fonts;
648
649 const TypeInfo
650 *p;
651
652 ssize_t
653 i;
654
655 /*
656 Allocate type list.
657 */
658 assert(pattern != (char *) NULL);
659 assert(number_fonts != (size_t *) NULL);
660 if (IsEventLogging() != MagickFalse)
661 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
662 *number_fonts=0;
663 p=GetTypeInfo("*",exception);
664 if (p == (const TypeInfo *) NULL)
665 return((char **) NULL);
666 fonts=(char **) AcquireQuantumMemory((size_t)
667 GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts));
668 if (fonts == (char **) NULL)
669 return((char **) NULL);
670 /*
671 Generate type list.
672 */
673 LockSemaphoreInfo(type_semaphore);
674 ResetSplayTreeIterator(type_cache);
675 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
676 for (i=0; p != (const TypeInfo *) NULL; )
677 {
678 if ((p->stealth == MagickFalse) &&
679 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
680 fonts[i++]=ConstantString(p->name);
681 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
682 }
683 UnlockSemaphoreInfo(type_semaphore);
684 qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeCompare);
685 fonts[i]=(char *) NULL;
686 *number_fonts=(size_t) i;
687 return(fonts);
688}
689
690/*
691%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692% %
693% %
694% %
695+ I s T y p e T r e e I n s t a n t i a t e d %
696% %
697% %
698% %
699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
700%
701% IsTypeTreeInstantiated() determines if the type tree is instantiated. If
702% not, it instantiates the tree and returns it.
703%
704% The format of the IsTypeInstantiated method is:
705%
706% MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception)
707%
708% A description of each parameter follows.
709%
710% o exception: return any errors or warnings in this structure.
711%
712*/
713
714#if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
715MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_cache,
716 ExceptionInfo *exception)
717{
718#if !defined(FC_FULLNAME)
719#define FC_FULLNAME "fullname"
720#endif
721
722 char
723 extension[MagickPathExtent],
724 name[MagickPathExtent];
725
726 FcBool
727 result;
728
729 FcChar8
730 *family,
731 *file,
732 *fullname,
733 *style;
734
735 FcConfig
736 *font_config;
737
738 FcFontSet
739 *font_set;
740
741 FcObjectSet
742 *object_set;
743
744 FcPattern
745 *pattern;
746
747 FcResult
748 status;
749
750 int
751 slant,
752 width,
753 weight;
754
755 ssize_t
756 i;
757
759 *type_info;
760
761 /*
762 Load system fonts.
763 */
764 (void) exception;
765 result=FcInit();
766 if (result == 0)
767 return(MagickFalse);
768 font_config=FcConfigGetCurrent();
769 if (font_config == (FcConfig *) NULL)
770 return(MagickFalse);
771 FcConfigSetRescanInterval(font_config,0);
772 font_set=(FcFontSet *) NULL;
773 object_set=FcObjectSetBuild(FC_FULLNAME,FC_FAMILY,FC_STYLE,FC_SLANT,
774 FC_WIDTH,FC_WEIGHT,FC_FILE,(char *) NULL);
775 if (object_set != (FcObjectSet *) NULL)
776 {
777 pattern=FcPatternCreate();
778 if (pattern != (FcPattern *) NULL)
779 {
780 font_set=FcFontList(font_config,pattern,object_set);
781 FcPatternDestroy(pattern);
782 }
783 FcObjectSetDestroy(object_set);
784 }
785 if (font_set == (FcFontSet *) NULL)
786 {
787 FcConfigDestroy(font_config);
788 return(MagickFalse);
789 }
790 for (i=0; i < (ssize_t) font_set->nfont; i++)
791 {
792 status=FcPatternGetString(font_set->fonts[i],FC_FAMILY,0,&family);
793 if (status != FcResultMatch)
794 continue;
795 status=FcPatternGetString(font_set->fonts[i],FC_FILE,0,&file);
796 if (status != FcResultMatch)
797 continue;
798 *extension='\0';
799 GetPathComponent((const char *) file,ExtensionPath,extension);
800 if ((*extension != '\0') && (LocaleCompare(extension,"gz") == 0))
801 continue;
802 type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
803 if (type_info == (TypeInfo *) NULL)
804 continue;
805 (void) memset(type_info,0,sizeof(*type_info));
806 type_info->path=ConstantString("System Fonts");
807 type_info->signature=MagickCoreSignature;
808 (void) CopyMagickString(name,"Unknown",MagickPathExtent);
809 status=FcPatternGetString(font_set->fonts[i],FC_FULLNAME,0,&fullname);
810 if ((status == FcResultMatch) && (fullname != (FcChar8 *) NULL))
811 (void) CopyMagickString(name,(const char *) fullname,MagickPathExtent);
812 else
813 {
814 if (family != (FcChar8 *) NULL)
815 (void) CopyMagickString(name,(const char *) family,MagickPathExtent);
816 status=FcPatternGetString(font_set->fonts[i],FC_STYLE,0,&style);
817 if ((status == FcResultMatch) && (style != (FcChar8 *) NULL) &&
818 (LocaleCompare((const char *) style,"Regular") != 0))
819 {
820 (void) ConcatenateMagickString(name," ",MagickPathExtent);
821 (void) ConcatenateMagickString(name,(const char *) style,
822 MagickPathExtent);
823 }
824 }
825 type_info->name=ConstantString(name);
826 (void) SubstituteString(&type_info->name," ","-");
827 type_info->family=ConstantString((const char *) family);
828 status=FcPatternGetInteger(font_set->fonts[i],FC_SLANT,0,&slant);
829 type_info->style=NormalStyle;
830 if (slant == FC_SLANT_ITALIC)
831 type_info->style=ItalicStyle;
832 if (slant == FC_SLANT_OBLIQUE)
833 type_info->style=ObliqueStyle;
834 status=FcPatternGetInteger(font_set->fonts[i],FC_WIDTH,0,&width);
835 type_info->stretch=NormalStretch;
836 if (width >= FC_WIDTH_ULTRACONDENSED)
837 type_info->stretch=UltraCondensedStretch;
838 if (width >= FC_WIDTH_EXTRACONDENSED)
839 type_info->stretch=ExtraCondensedStretch;
840 if (width >= FC_WIDTH_CONDENSED)
841 type_info->stretch=CondensedStretch;
842 if (width >= FC_WIDTH_SEMICONDENSED)
843 type_info->stretch=SemiCondensedStretch;
844 if (width >= FC_WIDTH_NORMAL)
845 type_info->stretch=NormalStretch;
846 if (width >= FC_WIDTH_SEMIEXPANDED)
847 type_info->stretch=SemiExpandedStretch;
848 if (width >= FC_WIDTH_EXPANDED)
849 type_info->stretch=ExpandedStretch;
850 if (width >= FC_WIDTH_EXTRAEXPANDED)
851 type_info->stretch=ExtraExpandedStretch;
852 if (width >= FC_WIDTH_ULTRAEXPANDED)
853 type_info->stretch=UltraExpandedStretch;
854 type_info->weight=400;
855 status=FcPatternGetInteger(font_set->fonts[i],FC_WEIGHT,0,&weight);
856 if (weight >= FC_WEIGHT_THIN)
857 type_info->weight=100;
858 if (weight >= FC_WEIGHT_EXTRALIGHT)
859 type_info->weight=200;
860 if (weight >= FC_WEIGHT_LIGHT)
861 type_info->weight=300;
862 if (weight >= FC_WEIGHT_NORMAL)
863 type_info->weight=400;
864 if (weight >= FC_WEIGHT_MEDIUM)
865 type_info->weight=500;
866 if (weight >= FC_WEIGHT_DEMIBOLD)
867 type_info->weight=600;
868 if (weight >= FC_WEIGHT_BOLD)
869 type_info->weight=700;
870 if (weight >= FC_WEIGHT_EXTRABOLD)
871 type_info->weight=800;
872 if (weight >= FC_WEIGHT_BLACK)
873 type_info->weight=900;
874 type_info->glyphs=ConstantString((const char *) file);
875 (void) AddValueToSplayTree(type_cache,type_info->name,type_info);
876 }
877 FcFontSetDestroy(font_set);
878 FcConfigDestroy(font_config);
879 return(MagickTrue);
880}
881#endif
882
883static MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception)
884{
885 if (type_cache == (SplayTreeInfo *) NULL)
886 {
887 if (type_semaphore == (SemaphoreInfo *) NULL)
888 ActivateSemaphoreInfo(&type_semaphore);
889 LockSemaphoreInfo(type_semaphore);
890 if (type_cache == (SplayTreeInfo *) NULL)
891 {
893 *splay_tree;
894
895 splay_tree=AcquireTypeCache(MagickTypeFilename,exception);
896#if defined(MAGICKCORE_WINDOWS_SUPPORT)
897 (void) NTAcquireTypeCache(splay_tree,exception);
898#endif
899#if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
900 (void) LoadFontConfigFonts(splay_tree,exception);
901#endif
902 type_cache=splay_tree;
903 }
904 UnlockSemaphoreInfo(type_semaphore);
905 }
906 return(type_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
907}
908
909/*
910%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
911% %
912% %
913% %
914% L i s t T y p e I n f o %
915% %
916% %
917% %
918%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
919%
920% ListTypeInfo() lists the fonts to a file.
921%
922% The format of the ListTypeInfo method is:
923%
924% MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
925%
926% A description of each parameter follows.
927%
928% o file: An pointer to a FILE.
929%
930% o exception: return any errors or warnings in this structure.
931%
932*/
933MagickExport MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
934{
935 char
936 weight[MagickPathExtent];
937
938 const char
939 *family,
940 *glyphs,
941 *name,
942 *path,
943 *stretch,
944 *style;
945
946 const TypeInfo
947 **type_info;
948
949 ssize_t
950 i;
951
952 size_t
953 number_fonts;
954
955 if (file == (FILE *) NULL)
956 file=stdout;
957 number_fonts=0;
958 type_info=GetTypeInfoList("*",&number_fonts,exception);
959 if (type_info == (const TypeInfo **) NULL)
960 return(MagickFalse);
961 *weight='\0';
962 path=(const char *) NULL;
963 for (i=0; i < (ssize_t) number_fonts; i++)
964 {
965 if (type_info[i]->stealth != MagickFalse)
966 continue;
967 if (((path == (const char *) NULL) ||
968 (LocaleCompare(path,type_info[i]->path) != 0)) &&
969 (type_info[i]->path != (char *) NULL))
970 (void) FormatLocaleFile(file,"\nPath: %s\n",type_info[i]->path);
971 path=type_info[i]->path;
972 name="unknown";
973 if (type_info[i]->name != (char *) NULL)
974 name=type_info[i]->name;
975 family="unknown";
976 if (type_info[i]->family != (char *) NULL)
977 family=type_info[i]->family;
978 style=CommandOptionToMnemonic(MagickStyleOptions,type_info[i]->style);
979 stretch=CommandOptionToMnemonic(MagickStretchOptions,type_info[i]->stretch);
980 glyphs="unknown";
981 if (type_info[i]->glyphs != (char *) NULL)
982 glyphs=type_info[i]->glyphs;
983 (void) FormatLocaleString(weight,MagickPathExtent,"%.20g",(double)
984 type_info[i]->weight);
985 (void) FormatLocaleFile(file," Font: %s\n",name);
986 (void) FormatLocaleFile(file," family: %s\n",family);
987 (void) FormatLocaleFile(file," style: %s\n",style);
988 (void) FormatLocaleFile(file," stretch: %s\n",stretch);
989 (void) FormatLocaleFile(file," weight: %s\n",weight);
990 (void) FormatLocaleFile(file," glyphs: %s\n",glyphs);
991 }
992 (void) fflush(file);
993 type_info=(const TypeInfo **) RelinquishMagickMemory((void *) type_info);
994 return(MagickTrue);
995}
996
997/*
998%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999% %
1000% %
1001% %
1002+ L o a d T y p e C a c h e %
1003% %
1004% %
1005% %
1006%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1007%
1008% LoadTypeCache() loads the type configurations which provides a mapping
1009% between type attributes and a type name.
1010%
1011% The format of the LoadTypeCache method is:
1012%
1013% MagickBooleanType LoadTypeCache(SplayTreeInfo *cache,const char *xml,
1014% const char *filename,const size_t depth,ExceptionInfo *exception)
1015%
1016% A description of each parameter follows:
1017%
1018% o xml: The type list in XML format.
1019%
1020% o filename: The type list filename.
1021%
1022% o depth: depth of <include /> statements.
1023%
1024% o exception: return any errors or warnings in this structure.
1025%
1026*/
1027
1028static inline MagickBooleanType SetTypeNodePath(const char *filename,
1029 char *font_path,const char *token,char **target)
1030{
1031 char
1032 *path;
1033
1034 path=ConstantString(token);
1035#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1036 if (strchr(path,'@') != (char *) NULL)
1037 SubstituteString(&path,"@ghostscript_font_path@",font_path);
1038#endif
1039 if (IsPathAccessible(path) == MagickFalse)
1040 {
1041 /*
1042 Relative path.
1043 */
1044 path=DestroyString(path);
1045 GetPathComponent(filename,HeadPath,font_path);
1046 (void) ConcatenateMagickString(font_path,DirectorySeparator,
1047 MagickPathExtent);
1048 (void) ConcatenateMagickString(font_path,token,MagickPathExtent);
1049 path=ConstantString(font_path);
1050#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1051 if (strchr(path,'@') != (char *) NULL)
1052 SubstituteString(&path,"@ghostscript_font_path@","");
1053#endif
1054 if (IsPathAccessible(path) == MagickFalse)
1055 {
1056 path=DestroyString(path);
1057 return(MagickFalse);
1058 }
1059 }
1060
1061 *target=path;
1062 return(MagickTrue);
1063}
1064
1065static MagickBooleanType LoadTypeCache(SplayTreeInfo *cache,const char *xml,
1066 const char *filename,const size_t depth,ExceptionInfo *exception)
1067{
1068 char
1069 font_path[MagickPathExtent],
1070 keyword[MagickPathExtent],
1071 *token;
1072
1073 const char
1074 *q;
1075
1076 MagickStatusType
1077 status;
1078
1079 size_t
1080 extent;
1081
1082 TypeInfo
1083 *type_info;
1084
1085 /*
1086 Load the type map file.
1087 */
1088 if (IsEventLogging() != MagickFalse)
1089 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1090 "Loading type configure file \"%s\" ...",filename);
1091 if (xml == (const char *) NULL)
1092 return(MagickFalse);
1093 status=MagickTrue;
1094 type_info=(TypeInfo *) NULL;
1095 token=AcquireString(xml);
1096 extent=strlen(token)+MagickPathExtent;
1097#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1098 /*
1099 Determine the Ghostscript font path.
1100 */
1101 *font_path='\0';
1102 if (NTGhostscriptFonts(font_path,MagickPathExtent-2) != MagickFalse)
1103 (void) ConcatenateMagickString(font_path,DirectorySeparator,
1104 MagickPathExtent);
1105#endif
1106 for (q=(char *) xml; *q != '\0'; )
1107 {
1108 /*
1109 Interpret XML.
1110 */
1111 (void) GetNextToken(q,&q,extent,token);
1112 if (*token == '\0')
1113 break;
1114 (void) CopyMagickString(keyword,token,MagickPathExtent);
1115 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1116 {
1117 /*
1118 Doctype element.
1119 */
1120 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1121 (void) GetNextToken(q,&q,extent,token);
1122 continue;
1123 }
1124 if (LocaleNCompare(keyword,"<!--",4) == 0)
1125 {
1126 /*
1127 Comment element.
1128 */
1129 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1130 (void) GetNextToken(q,&q,extent,token);
1131 continue;
1132 }
1133 if (LocaleCompare(keyword,"<include") == 0)
1134 {
1135 /*
1136 Include element.
1137 */
1138 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1139 {
1140 (void) CopyMagickString(keyword,token,MagickPathExtent);
1141 (void) GetNextToken(q,&q,extent,token);
1142 if (*token != '=')
1143 continue;
1144 (void) GetNextToken(q,&q,extent,token);
1145 if (LocaleCompare(keyword,"file") == 0)
1146 {
1147 if (depth > MagickMaxRecursionDepth)
1148 (void) ThrowMagickException(exception,GetMagickModule(),
1149 ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
1150 else
1151 {
1152 char
1153 path[MagickPathExtent],
1154 *file_xml;
1155
1157 *sans_exception;
1158
1159 *path='\0';
1160 GetPathComponent(filename,HeadPath,path);
1161 if (*path != '\0')
1162 (void) ConcatenateMagickString(path,DirectorySeparator,
1163 MagickPathExtent);
1164 if (*token == *DirectorySeparator)
1165 (void) CopyMagickString(path,token,MagickPathExtent);
1166 else
1167 (void) ConcatenateMagickString(path,token,MagickPathExtent);
1168 sans_exception=AcquireExceptionInfo();
1169 file_xml=FileToString(path,~0UL,sans_exception);
1170 sans_exception=DestroyExceptionInfo(sans_exception);
1171 if (file_xml != (char *) NULL)
1172 {
1173 status&=(MagickStatusType) LoadTypeCache(cache,file_xml,
1174 path,depth+1,exception);
1175 file_xml=(char *) RelinquishMagickMemory(file_xml);
1176 }
1177 }
1178 }
1179 }
1180 continue;
1181 }
1182 if (LocaleCompare(keyword,"<type") == 0)
1183 {
1184 /*
1185 Type element.
1186 */
1187 type_info=(TypeInfo *) AcquireCriticalMemory(sizeof(*type_info));
1188 (void) memset(type_info,0,sizeof(*type_info));
1189 type_info->path=ConstantString(filename);
1190 type_info->signature=MagickCoreSignature;
1191 continue;
1192 }
1193 if (type_info == (TypeInfo *) NULL)
1194 continue;
1195 if ((LocaleCompare(keyword,"/>") == 0) ||
1196 (LocaleCompare(keyword,"</policy>") == 0))
1197 {
1198 status=AddValueToSplayTree(cache,type_info->name,type_info);
1199 if (status == MagickFalse)
1200 (void) ThrowMagickException(exception,GetMagickModule(),
1201 ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
1202 type_info=(TypeInfo *) NULL;
1203 continue;
1204 }
1205 (void) GetNextToken(q,(const char **) NULL,extent,token);
1206 if (*token != '=')
1207 continue;
1208 (void) GetNextToken(q,&q,extent,token);
1209 (void) GetNextToken(q,&q,extent,token);
1210 switch (*keyword)
1211 {
1212 case 'E':
1213 case 'e':
1214 {
1215 if (LocaleCompare((char *) keyword,"encoding") == 0)
1216 {
1217 type_info->encoding=ConstantString(token);
1218 break;
1219 }
1220 break;
1221 }
1222 case 'F':
1223 case 'f':
1224 {
1225 if (LocaleCompare((char *) keyword,"face") == 0)
1226 {
1227 type_info->face=StringToUnsignedLong(token);
1228 break;
1229 }
1230 if (LocaleCompare((char *) keyword,"family") == 0)
1231 {
1232 type_info->family=ConstantString(token);
1233 break;
1234 }
1235 if (LocaleCompare((char *) keyword,"format") == 0)
1236 {
1237 type_info->format=ConstantString(token);
1238 break;
1239 }
1240 if (LocaleCompare((char *) keyword,"foundry") == 0)
1241 {
1242 type_info->foundry=ConstantString(token);
1243 break;
1244 }
1245 if (LocaleCompare((char *) keyword,"fullname") == 0)
1246 {
1247 type_info->description=ConstantString(token);
1248 break;
1249 }
1250 break;
1251 }
1252 case 'G':
1253 case 'g':
1254 {
1255 if (LocaleCompare((char *) keyword,"glyphs") == 0)
1256 {
1257 if (SetTypeNodePath(filename,font_path,token,&type_info->glyphs) ==
1258 MagickFalse)
1259 type_info=(TypeInfo *) DestroyTypeNode(type_info);
1260 break;
1261 }
1262 break;
1263 }
1264 case 'M':
1265 case 'm':
1266 {
1267 if (LocaleCompare((char *) keyword,"metrics") == 0)
1268 {
1269 if (SetTypeNodePath(filename,font_path,token,&type_info->metrics) ==
1270 MagickFalse)
1271 type_info=(TypeInfo *) DestroyTypeNode(type_info);
1272 break;
1273 }
1274 break;
1275 }
1276 case 'N':
1277 case 'n':
1278 {
1279 if (LocaleCompare((char *) keyword,"name") == 0)
1280 {
1281 type_info->name=ConstantString(token);
1282 break;
1283 }
1284 break;
1285 }
1286 case 'S':
1287 case 's':
1288 {
1289 if (LocaleCompare((char *) keyword,"stealth") == 0)
1290 {
1291 type_info->stealth=IsStringTrue(token);
1292 break;
1293 }
1294 if (LocaleCompare((char *) keyword,"stretch") == 0)
1295 {
1296 type_info->stretch=(StretchType) ParseCommandOption(
1297 MagickStretchOptions,MagickFalse,token);
1298 break;
1299 }
1300 if (LocaleCompare((char *) keyword,"style") == 0)
1301 {
1302 type_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
1303 MagickFalse,token);
1304 break;
1305 }
1306 break;
1307 }
1308 case 'W':
1309 case 'w':
1310 {
1311 if (LocaleCompare((char *) keyword,"weight") == 0)
1312 {
1313 ssize_t
1314 weight;
1315
1316 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
1317 if (weight == -1)
1318 weight=(ssize_t) StringToUnsignedLong(token);
1319 type_info->weight=(size_t) weight;
1320 break;
1321 }
1322 break;
1323 }
1324 default:
1325 break;
1326 }
1327 }
1328 token=(char *) RelinquishMagickMemory(token);
1329 return(status != 0 ? MagickTrue : MagickFalse);
1330}
1331
1332/*
1333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1334% %
1335% %
1336% %
1337+ T y p e C o m p o n e n t G e n e s i s %
1338% %
1339% %
1340% %
1341%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342%
1343% TypeComponentGenesis() instantiates the type component.
1344%
1345% The format of the TypeComponentGenesis method is:
1346%
1347% MagickBooleanType TypeComponentGenesis(void)
1348%
1349*/
1350MagickPrivate MagickBooleanType TypeComponentGenesis(void)
1351{
1352 if (type_semaphore == (SemaphoreInfo *) NULL)
1353 type_semaphore=AcquireSemaphoreInfo();
1354 return(MagickTrue);
1355}
1356
1357/*
1358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359% %
1360% %
1361% %
1362+ T y p e C o m p o n e n t T e r m i n u s %
1363% %
1364% %
1365% %
1366%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1367%
1368% TypeComponentTerminus() destroy type component.
1369%
1370% The format of the TypeComponentTerminus method is:
1371%
1372% void TypeComponentTerminus(void)
1373%
1374*/
1375MagickPrivate void TypeComponentTerminus(void)
1376{
1377 if (type_semaphore == (SemaphoreInfo *) NULL)
1378 ActivateSemaphoreInfo(&type_semaphore);
1379 LockSemaphoreInfo(type_semaphore);
1380 if (type_cache != (SplayTreeInfo *) NULL)
1381 type_cache=DestroySplayTree(type_cache);
1382 UnlockSemaphoreInfo(type_semaphore);
1383 RelinquishSemaphoreInfo(&type_semaphore);
1384}