2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % TTTTT Y Y PPPP EEEEE %
13 % MagickCore Image Type Methods %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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/hashmap.h"
50 #include "MagickCore/log.h"
51 #include "MagickCore/memory_.h"
52 #include "MagickCore/nt-feature.h"
53 #include "MagickCore/nt-base-private.h"
54 #include "MagickCore/option.h"
55 #include "MagickCore/semaphore.h"
56 #include "MagickCore/splay-tree.h"
57 #include "MagickCore/string_.h"
58 #include "MagickCore/string-private.h"
59 #include "MagickCore/type.h"
60 #include "MagickCore/type-private.h"
61 #include "MagickCore/token.h"
62 #include "MagickCore/utility.h"
63 #include "MagickCore/utility-private.h"
64 #include "MagickCore/xml-tree.h"
65 #if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
66 # include "fontconfig/fontconfig.h"
67 #if (FC_VERSION < 20209)
68 #undef FC_WEIGHT_LIGHT
69 #define FC_WIDTH "width" /* Int */
70 #define FC_WIDTH_ULTRACONDENSED 50
71 #define FC_WIDTH_EXTRACONDENSED 63
72 #define FC_WIDTH_CONDENSED 75
73 #define FC_WIDTH_SEMICONDENSED 87
74 #define FC_WIDTH_NORMAL 100
75 #define FC_WIDTH_SEMIEXPANDED 113
76 #define FC_WIDTH_EXPANDED 125
77 #define FC_WIDTH_EXTRAEXPANDED 150
78 #define FC_WIDTH_ULTRAEXPANDED 200
80 #define FC_WEIGHT_THIN 0
81 #define FC_WEIGHT_EXTRALIGHT 40
82 #define FC_WEIGHT_ULTRALIGHT FC_WEIGHT_EXTRALIGHT
83 #define FC_WEIGHT_LIGHT 50
84 #define FC_WEIGHT_BOOK 75
85 #define FC_WEIGHT_REGULAR 80
86 #define FC_WEIGHT_NORMAL FC_WEIGHT_REGULAR
87 #define FC_WEIGHT_MEDIUM 100
88 #define FC_WEIGHT_DEMIBOLD 180
89 #define FC_WEIGHT_SEMIBOLD FC_WEIGHT_DEMIBOLD
90 #define FC_WEIGHT_BOLD 200
91 #define FC_WEIGHT_EXTRABOLD 205
92 #define FC_WEIGHT_ULTRABOLD FC_WEIGHT_EXTRABOLD
93 #define FC_WEIGHT_BLACK 210
94 #define FC_WEIGHT_HEAVY FC_WEIGHT_BLACK
97 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
98 # include "MagickCore/nt-feature.h"
104 #define MagickTypeFilename "type.xml"
110 *TypeMap = (const char *)
111 "<?xml version=\"1.0\"?>"
113 " <type stealth=\"True\" name=\"fixed\" family=\"helvetica\"/>"
114 " <type stealth=\"True\" name=\"helvetica\" family=\"helvetica\"/>"
121 *type_semaphore = (SemaphoreInfo *) NULL;
124 *type_cache = (SplayTreeInfo *) NULL;
127 Forward declarations.
129 static MagickBooleanType
130 IsTypeTreeInstantiated(ExceptionInfo *),
131 LoadTypeCache(SplayTreeInfo *,const char *,const char *,const size_t,
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % A c q u i r e T y p e S p l a y T r e e %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % AcquireTypeCache() caches one or more type configuration files which
146 % provides a mapping between type attributes and a type name.
148 % The format of the AcquireTypeCache method is:
150 % SplayTreeInfo *AcquireTypeCache(const char *filename,
151 % ExceptionInfo *exception)
153 % A description of each parameter follows:
155 % o filename: the font file name.
157 % o exception: return any errors or warnings in this structure.
161 static void *DestroyTypeNode(void *type_info)
166 p=(TypeInfo *) type_info;
167 if (p->path != (char *) NULL)
168 p->path=DestroyString(p->path);
169 if (p->name != (char *) NULL)
170 p->name=DestroyString(p->name);
171 if (p->description != (char *) NULL)
172 p->description=DestroyString(p->description);
173 if (p->family != (char *) NULL)
174 p->family=DestroyString(p->family);
175 if (p->encoding != (char *) NULL)
176 p->encoding=DestroyString(p->encoding);
177 if (p->foundry != (char *) NULL)
178 p->foundry=DestroyString(p->foundry);
179 if (p->format != (char *) NULL)
180 p->format=DestroyString(p->format);
181 if (p->metrics != (char *) NULL)
182 p->metrics=DestroyString(p->metrics);
183 if (p->glyphs != (char *) NULL)
184 p->glyphs=DestroyString(p->glyphs);
185 return(RelinquishMagickMemory(p));
188 static SplayTreeInfo *AcquireTypeCache(const char *filename,
189 ExceptionInfo *exception)
197 type_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
199 if (type_cache == (SplayTreeInfo *) NULL)
200 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
202 #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
215 options=GetConfigureOptions(filename,exception);
216 option=(const StringInfo *) GetNextValueInLinkedList(options);
217 while (option != (const StringInfo *) NULL)
219 (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent);
220 status&=LoadTypeCache(type_cache,(const char *)
221 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
222 option=(const StringInfo *) GetNextValueInLinkedList(options);
224 options=DestroyConfigureOptions(options);
225 font_path=GetEnvironmentValue("MAGICK_FONT_PATH");
226 if (font_path != (char *) NULL)
232 Search MAGICK_FONT_PATH.
234 (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",font_path,
235 DirectorySeparator,filename);
236 option=FileToString(path,~0UL,exception);
237 if (option != (void *) NULL)
239 status&=LoadTypeCache(type_cache,option,path,0,exception);
240 option=DestroyString(option);
242 font_path=DestroyString(font_path);
246 if (GetNumberOfNodesInSplayTree(type_cache) == 0)
247 status&=LoadTypeCache(type_cache,TypeMap,"built-in",0,exception);
252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 + G e t T y p e I n f o %
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 % GetTypeInfo searches the type list for the specified name and if found
263 % returns attributes for that type.
265 % The format of the GetTypeInfo method is:
267 % const TypeInfo *GetTypeInfo(const char *name,ExceptionInfo *exception)
269 % A description of each parameter follows:
271 % o name: the type name.
273 % o exception: return any errors or warnings in this structure.
276 MagickExport const TypeInfo *GetTypeInfo(const char *name,
277 ExceptionInfo *exception)
282 assert(exception != (ExceptionInfo *) NULL);
283 if (IsTypeTreeInstantiated(exception) == MagickFalse)
284 return((const TypeInfo *) NULL);
285 LockSemaphoreInfo(type_semaphore);
286 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
288 ResetSplayTreeIterator(type_cache);
289 type_info=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
290 UnlockSemaphoreInfo(type_semaphore);
293 type_info=(const TypeInfo *) GetValueFromSplayTree(type_cache,name);
294 UnlockSemaphoreInfo(type_semaphore);
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 + G e t T y p e I n f o B y F a m i l y %
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % GetTypeInfoByFamily() searches the type list for the specified family and if
310 % found returns attributes for that type.
312 % Type substitution and scoring algorithm contributed by Bob Friesenhahn.
314 % The format of the GetTypeInfoByFamily method is:
316 % const TypeInfo *GetTypeInfoByFamily(const char *family,
317 % const StyleType style,const StretchType stretch,
318 % const size_t weight,ExceptionInfo *exception)
320 % A description of each parameter follows:
322 % o family: the type family.
324 % o style: the type style.
326 % o stretch: the type stretch.
328 % o weight: the type weight.
330 % o exception: return any errors or warnings in this structure.
334 static inline size_t MagickMax(const size_t x,const size_t y)
341 static inline size_t MagickMin(const size_t x,const size_t y)
348 MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
349 const StyleType style,const StretchType stretch,const size_t weight,
350 ExceptionInfo *exception)
352 typedef struct _Fontmap
362 register const TypeInfo
374 { "fixed", "courier" },
375 { "modern","courier" },
376 { "monotype corsiva", "courier" },
377 { "news gothic", "helvetica" },
378 { "system", "courier" },
379 { "terminal", "courier" },
380 { "wingdings", "symbol" },
389 Check for an exact type match.
391 (void) GetTypeInfo("*",exception);
392 if (type_cache == (SplayTreeInfo *) NULL)
393 return((TypeInfo *) NULL);
394 LockSemaphoreInfo(type_semaphore);
395 ResetSplayTreeIterator(type_cache);
396 type_info=(const TypeInfo *) NULL;
397 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
398 while (p != (const TypeInfo *) NULL)
400 if (p->family == (char *) NULL)
402 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
405 if (family == (const char *) NULL)
407 if ((LocaleCompare(p->family,"arial") != 0) &&
408 (LocaleCompare(p->family,"helvetica") != 0))
410 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
415 if (LocaleCompare(p->family,family) != 0)
417 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
420 if ((style != UndefinedStyle) && (style != AnyStyle) && (p->style != style))
422 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
425 if ((stretch != UndefinedStretch) && (stretch != AnyStretch) &&
426 (p->stretch != stretch))
428 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
431 if ((weight != 0) && (p->weight != weight))
433 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
439 UnlockSemaphoreInfo(type_semaphore);
440 if (type_info != (const TypeInfo *) NULL)
443 Check for types in the same family.
446 LockSemaphoreInfo(type_semaphore);
447 ResetSplayTreeIterator(type_cache);
448 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
449 while (p != (const TypeInfo *) NULL)
451 if (p->family == (char *) NULL)
453 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
456 if (family == (const char *) NULL)
458 if ((LocaleCompare(p->family,"arial") != 0) &&
459 (LocaleCompare(p->family,"helvetica") != 0))
461 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
466 if (LocaleCompare(p->family,family) != 0)
468 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
472 if ((style == UndefinedStyle) || (style == AnyStyle) || (p->style == style))
475 if (((style == ItalicStyle) || (style == ObliqueStyle)) &&
476 ((p->style == ItalicStyle) || (p->style == ObliqueStyle)))
481 score+=(16*(800-((ssize_t) MagickMax(MagickMin(weight,900),p->weight)-
482 (ssize_t) MagickMin(MagickMin(weight,900),p->weight))))/800;
483 if ((stretch == UndefinedStretch) || (stretch == AnyStretch))
487 range=(ssize_t) UltraExpandedStretch-(ssize_t) NormalStretch;
488 score+=(8*(range-((ssize_t) MagickMax(stretch,p->stretch)-
489 (ssize_t) MagickMin(stretch,p->stretch))))/range;
491 if (score > max_score)
496 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
498 UnlockSemaphoreInfo(type_semaphore);
499 if (type_info != (const TypeInfo *) NULL)
502 Check for table-based substitution match.
504 for (i=0; fontmap[i].name != (char *) NULL; i++)
506 if (family == (const char *) NULL)
508 if ((LocaleCompare(fontmap[i].name,"arial") != 0) &&
509 (LocaleCompare(fontmap[i].name,"helvetica") != 0))
513 if (LocaleCompare(fontmap[i].name,family) != 0)
515 type_info=GetTypeInfoByFamily(fontmap[i].substitute,style,stretch,weight,
519 if (type_info != (const TypeInfo *) NULL)
521 (void) ThrowMagickException(exception,GetMagickModule(),TypeError,
522 "FontSubstitutionRequired","`%s'",type_info->family);
525 if (family != (const char *) NULL)
526 type_info=GetTypeInfoByFamily((const char *) NULL,style,stretch,weight,
532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
536 % G e t T y p e I n f o L i s t %
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 % GetTypeInfoList() returns any fonts that match the specified pattern.
544 % The format of the GetTypeInfoList function is:
546 % const TypeInfo **GetTypeInfoList(const char *pattern,
547 % size_t *number_fonts,ExceptionInfo *exception)
549 % A description of each parameter follows:
551 % o pattern: Specifies a pointer to a text string containing a pattern.
553 % o number_fonts: This integer returns the number of types in the list.
555 % o exception: return any errors or warnings in this structure.
559 #if defined(__cplusplus) || defined(c_plusplus)
563 static int TypeInfoCompare(const void *x,const void *y)
569 p=(const TypeInfo **) x,
570 q=(const TypeInfo **) y;
571 if (LocaleCompare((*p)->path,(*q)->path) == 0)
572 return(LocaleCompare((*p)->name,(*q)->name));
573 return(LocaleCompare((*p)->path,(*q)->path));
576 #if defined(__cplusplus) || defined(c_plusplus)
580 MagickExport const TypeInfo **GetTypeInfoList(const char *pattern,
581 size_t *number_fonts,ExceptionInfo *exception)
586 register const TypeInfo
595 assert(pattern != (char *) NULL);
596 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
597 assert(number_fonts != (size_t *) NULL);
599 p=GetTypeInfo("*",exception);
600 if (p == (const TypeInfo *) NULL)
601 return((const TypeInfo **) NULL);
602 fonts=(const TypeInfo **) AcquireQuantumMemory((size_t)
603 GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts));
604 if (fonts == (const TypeInfo **) NULL)
605 return((const TypeInfo **) NULL);
609 LockSemaphoreInfo(type_semaphore);
610 ResetSplayTreeIterator(type_cache);
611 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
612 for (i=0; p != (const TypeInfo *) NULL; )
614 if ((p->stealth == MagickFalse) &&
615 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
617 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
619 UnlockSemaphoreInfo(type_semaphore);
620 qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeInfoCompare);
621 fonts[i]=(TypeInfo *) NULL;
622 *number_fonts=(size_t) i;
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 % G e t T y p e L i s t %
635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
637 % GetTypeList() returns any fonts that match the specified pattern.
639 % The format of the GetTypeList function is:
641 % char **GetTypeList(const char *pattern,size_t *number_fonts,
642 % ExceptionInfo *exception)
644 % A description of each parameter follows:
646 % o pattern: Specifies a pointer to a text string containing a pattern.
648 % o number_fonts: This integer returns the number of fonts in the list.
650 % o exception: return any errors or warnings in this structure.
654 #if defined(__cplusplus) || defined(c_plusplus)
658 static int TypeCompare(const void *x,const void *y)
666 return(LocaleCompare(*p,*q));
669 #if defined(__cplusplus) || defined(c_plusplus)
673 MagickExport char **GetTypeList(const char *pattern,size_t *number_fonts,
674 ExceptionInfo *exception)
679 register const TypeInfo
688 assert(pattern != (char *) NULL);
689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
690 assert(number_fonts != (size_t *) NULL);
692 p=GetTypeInfo("*",exception);
693 if (p == (const TypeInfo *) NULL)
694 return((char **) NULL);
695 fonts=(char **) AcquireQuantumMemory((size_t)
696 GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts));
697 if (fonts == (char **) NULL)
698 return((char **) NULL);
702 LockSemaphoreInfo(type_semaphore);
703 ResetSplayTreeIterator(type_cache);
704 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
705 for (i=0; p != (const TypeInfo *) NULL; )
707 if ((p->stealth == MagickFalse) &&
708 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
709 fonts[i++]=ConstantString(p->name);
710 p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
712 UnlockSemaphoreInfo(type_semaphore);
713 qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeCompare);
714 fonts[i]=(char *) NULL;
715 *number_fonts=(size_t) i;
720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
724 + I s T y p e T r e e I n s t a n t i a t e d %
728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
730 % IsTypeTreeInstantiated() determines if the type tree is instantiated. If
731 % not, it instantiates the tree and returns it.
733 % The format of the IsTypeInstantiated method is:
735 % MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception)
737 % A description of each parameter follows.
739 % o exception: return any errors or warnings in this structure.
743 #if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
744 MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_cache,
745 ExceptionInfo *exception)
747 #if !defined(FC_FULLNAME)
748 #define FC_FULLNAME "fullname"
752 extension[MaxTextExtent],
791 font_config=FcInitLoadConfigAndFonts();
792 if (font_config == (FcConfig *) NULL)
794 font_set=(FcFontSet *) NULL;
795 object_set=FcObjectSetBuild(FC_FULLNAME,FC_FAMILY,FC_STYLE,FC_SLANT,
796 FC_WIDTH,FC_WEIGHT,FC_FILE,(char *) NULL);
797 if (object_set != (FcObjectSet *) NULL)
799 pattern=FcPatternCreate();
800 if (pattern != (FcPattern *) NULL)
802 font_set=FcFontList(0,pattern,object_set);
803 FcPatternDestroy(pattern);
805 FcObjectSetDestroy(object_set);
807 if (font_set == (FcFontSet *) NULL)
809 FcConfigDestroy(font_config);
812 for (i=0; i < (ssize_t) font_set->nfont; i++)
814 status=FcPatternGetString(font_set->fonts[i],FC_FAMILY,0,&family);
815 if (status != FcResultMatch)
817 status=FcPatternGetString(font_set->fonts[i],FC_FILE,0,&file);
818 if (status != FcResultMatch)
821 GetPathComponent((const char *) file,ExtensionPath,extension);
822 if ((*extension != '\0') && (LocaleCompare(extension,"gz") == 0))
824 type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
825 if (type_info == (TypeInfo *) NULL)
827 (void) ResetMagickMemory(type_info,0,sizeof(*type_info));
828 type_info->path=ConstantString("System Fonts");
829 type_info->signature=MagickSignature;
830 (void) CopyMagickString(name,"Unknown",MaxTextExtent);
831 status=FcPatternGetString(font_set->fonts[i],FC_FULLNAME,0,&fullname);
832 if ((status == FcResultMatch) && (fullname != (FcChar8 *) NULL))
833 (void) CopyMagickString(name,(const char *) fullname,MaxTextExtent);
836 if (family != (FcChar8 *) NULL)
837 (void) CopyMagickString(name,(const char *) family,MaxTextExtent);
838 status=FcPatternGetString(font_set->fonts[i],FC_STYLE,0,&style);
839 if ((status == FcResultMatch) && (style != (FcChar8 *) NULL) &&
840 (LocaleCompare((const char *) style,"Regular") != 0))
842 (void) ConcatenateMagickString(name," ",MaxTextExtent);
843 (void) ConcatenateMagickString(name,(const char *) style,
847 type_info->name=ConstantString(name);
848 (void) SubstituteString(&type_info->name," ","-");
849 type_info->family=ConstantString((const char *) family);
850 status=FcPatternGetInteger(font_set->fonts[i],FC_SLANT,0,&slant);
851 type_info->style=NormalStyle;
852 if (slant == FC_SLANT_ITALIC)
853 type_info->style=ItalicStyle;
854 if (slant == FC_SLANT_OBLIQUE)
855 type_info->style=ObliqueStyle;
856 status=FcPatternGetInteger(font_set->fonts[i],FC_WIDTH,0,&width);
857 type_info->stretch=NormalStretch;
858 if (width >= FC_WIDTH_ULTRACONDENSED)
859 type_info->stretch=UltraCondensedStretch;
860 if (width >= FC_WIDTH_EXTRACONDENSED)
861 type_info->stretch=ExtraCondensedStretch;
862 if (width >= FC_WIDTH_CONDENSED)
863 type_info->stretch=CondensedStretch;
864 if (width >= FC_WIDTH_SEMICONDENSED)
865 type_info->stretch=SemiCondensedStretch;
866 if (width >= FC_WIDTH_NORMAL)
867 type_info->stretch=NormalStretch;
868 if (width >= FC_WIDTH_SEMIEXPANDED)
869 type_info->stretch=SemiExpandedStretch;
870 if (width >= FC_WIDTH_EXPANDED)
871 type_info->stretch=ExpandedStretch;
872 if (width >= FC_WIDTH_EXTRAEXPANDED)
873 type_info->stretch=ExtraExpandedStretch;
874 if (width >= FC_WIDTH_ULTRAEXPANDED)
875 type_info->stretch=UltraExpandedStretch;
876 type_info->weight=400;
877 status=FcPatternGetInteger(font_set->fonts[i],FC_WEIGHT,0,&weight);
878 if (weight >= FC_WEIGHT_THIN)
879 type_info->weight=100;
880 if (weight >= FC_WEIGHT_EXTRALIGHT)
881 type_info->weight=200;
882 if (weight >= FC_WEIGHT_LIGHT)
883 type_info->weight=300;
884 if (weight >= FC_WEIGHT_NORMAL)
885 type_info->weight=400;
886 if (weight >= FC_WEIGHT_MEDIUM)
887 type_info->weight=500;
888 if (weight >= FC_WEIGHT_DEMIBOLD)
889 type_info->weight=600;
890 if (weight >= FC_WEIGHT_BOLD)
891 type_info->weight=700;
892 if (weight >= FC_WEIGHT_EXTRABOLD)
893 type_info->weight=800;
894 if (weight >= FC_WEIGHT_BLACK)
895 type_info->weight=900;
896 type_info->glyphs=ConstantString((const char *) file);
897 (void) AddValueToSplayTree(type_cache,type_info->name,type_info);
899 FcFontSetDestroy(font_set);
900 FcConfigDestroy(font_config);
905 static MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception)
907 if (type_cache == (SplayTreeInfo *) NULL)
909 if (type_semaphore == (SemaphoreInfo *) NULL)
910 ActivateSemaphoreInfo(&type_semaphore);
911 LockSemaphoreInfo(type_semaphore);
912 if (type_cache == (SplayTreeInfo *) NULL)
914 type_cache=AcquireTypeCache(MagickTypeFilename,exception);
915 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
916 (void) NTAcquireTypeCache(type_cache,exception);
918 #if defined(MAGICKCORE_FONTCONFIG_DELEGATE)
919 (void) LoadFontConfigFonts(type_cache,exception);
922 UnlockSemaphoreInfo(type_semaphore);
924 return(type_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 % L i s t T y p e I n f o %
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938 % ListTypeInfo() lists the fonts to a file.
940 % The format of the ListTypeInfo method is:
942 % MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
944 % A description of each parameter follows.
946 % o file: An pointer to a FILE.
948 % o exception: return any errors or warnings in this structure.
951 MagickExport MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
954 weight[MaxTextExtent];
973 if (file == (FILE *) NULL)
976 type_info=GetTypeInfoList("*",&number_fonts,exception);
977 if (type_info == (const TypeInfo **) NULL)
980 path=(const char *) NULL;
981 for (i=0; i < (ssize_t) number_fonts; i++)
983 if (type_info[i]->stealth != MagickFalse)
985 if (((path == (const char *) NULL) ||
986 (LocaleCompare(path,type_info[i]->path) != 0)) &&
987 (type_info[i]->path != (char *) NULL))
988 (void) FormatLocaleFile(file,"\nPath: %s\n",type_info[i]->path);
989 path=type_info[i]->path;
991 if (type_info[i]->name != (char *) NULL)
992 name=type_info[i]->name;
994 if (type_info[i]->family != (char *) NULL)
995 family=type_info[i]->family;
996 style=CommandOptionToMnemonic(MagickStyleOptions,type_info[i]->style);
997 stretch=CommandOptionToMnemonic(MagickStretchOptions,type_info[i]->stretch);
999 if (type_info[i]->glyphs != (char *) NULL)
1000 glyphs=type_info[i]->glyphs;
1001 (void) FormatLocaleString(weight,MaxTextExtent,"%.20g",(double)
1002 type_info[i]->weight);
1003 (void) FormatLocaleFile(file," Font: %s\n",name);
1004 (void) FormatLocaleFile(file," family: %s\n",family);
1005 (void) FormatLocaleFile(file," style: %s\n",style);
1006 (void) FormatLocaleFile(file," stretch: %s\n",stretch);
1007 (void) FormatLocaleFile(file," weight: %s\n",weight);
1008 (void) FormatLocaleFile(file," glyphs: %s\n",glyphs);
1010 (void) fflush(file);
1011 type_info=(const TypeInfo **) RelinquishMagickMemory((void *) type_info);
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1020 + L o a d T y p e L i s t %
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026 % LoadTypeCache() loads the type configurations which provides a mapping
1027 % between type attributes and a type name.
1029 % The format of the LoadTypeCache method is:
1031 % MagickBooleanType LoadTypeCache(SplayTreeInfo *type_cache,
1032 % const char *xml,const char *filename,const size_t depth,
1033 % ExceptionInfo *exception)
1035 % A description of each parameter follows:
1037 % o xml: The type list in XML format.
1039 % o filename: The type list filename.
1041 % o depth: depth of <include /> statements.
1043 % o exception: return any errors or warnings in this structure.
1047 static inline MagickBooleanType SetTypeNodePath(const char *filename,
1048 char *font_path,const char *token,char **target)
1053 path=ConstantString(token);
1054 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1055 if (strchr(path,'@') != (char *) NULL)
1056 SubstituteString(&path,"@ghostscript_font_path@",font_path);
1058 if (IsPathAccessible(path) == MagickFalse)
1063 path=DestroyString(path);
1064 GetPathComponent(filename,HeadPath,font_path);
1065 (void) ConcatenateMagickString(font_path,DirectorySeparator,
1067 (void) ConcatenateMagickString(font_path,token,MaxTextExtent);
1068 path=ConstantString(font_path);
1069 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1070 if (strchr(path,'@') != (char *) NULL)
1071 SubstituteString(&path,"@ghostscript_font_path@","");
1073 if (IsPathAccessible(path) == MagickFalse)
1075 path=DestroyString(path);
1076 return(MagickFalse);
1084 static MagickBooleanType LoadTypeCache(SplayTreeInfo *type_cache,
1085 const char *xml,const char *filename,const size_t depth,
1086 ExceptionInfo *exception)
1089 font_path[MaxTextExtent],
1090 keyword[MaxTextExtent],
1103 Load the type map file.
1105 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1106 "Loading type configure file \"%s\" ...",filename);
1107 if (xml == (const char *) NULL)
1108 return(MagickFalse);
1110 type_info=(TypeInfo *) NULL;
1111 token=AcquireString(xml);
1112 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1114 Determine the Ghostscript font path.
1117 if (NTGhostscriptFonts(font_path,MaxTextExtent-2))
1118 (void) ConcatenateMagickString(font_path,DirectorySeparator,MaxTextExtent);
1120 for (q=(char *) xml; *q != '\0'; )
1125 GetMagickToken(q,&q,token);
1128 (void) CopyMagickString(keyword,token,MaxTextExtent);
1129 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1134 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1135 GetMagickToken(q,&q,token);
1138 if (LocaleNCompare(keyword,"<!--",4) == 0)
1143 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1144 GetMagickToken(q,&q,token);
1147 if (LocaleCompare(keyword,"<include") == 0)
1152 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1154 (void) CopyMagickString(keyword,token,MaxTextExtent);
1155 GetMagickToken(q,&q,token);
1158 GetMagickToken(q,&q,token);
1159 if (LocaleCompare(keyword,"file") == 0)
1162 (void) ThrowMagickException(exception,GetMagickModule(),
1163 ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
1167 path[MaxTextExtent],
1174 GetPathComponent(filename,HeadPath,path);
1176 (void) ConcatenateMagickString(path,DirectorySeparator,
1178 if (*token == *DirectorySeparator)
1179 (void) CopyMagickString(path,token,MaxTextExtent);
1181 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1182 sans_exception=AcquireExceptionInfo();
1183 xml=FileToString(path,~0UL,sans_exception);
1184 sans_exception=DestroyExceptionInfo(sans_exception);
1185 if (xml != (char *) NULL)
1187 status&=LoadTypeCache(type_cache,xml,path,depth+1,
1189 xml=(char *) RelinquishMagickMemory(xml);
1196 if (LocaleCompare(keyword,"<type") == 0)
1201 type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
1202 if (type_info == (TypeInfo *) NULL)
1203 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1204 (void) ResetMagickMemory(type_info,0,sizeof(*type_info));
1205 type_info->path=ConstantString(filename);
1206 type_info->signature=MagickSignature;
1209 if (type_info == (TypeInfo *) NULL)
1211 if (LocaleCompare(keyword,"/>") == 0)
1213 status=AddValueToSplayTree(type_cache,type_info->name,type_info);
1214 if (status == MagickFalse)
1215 (void) ThrowMagickException(exception,GetMagickModule(),
1216 ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
1217 type_info=(TypeInfo *) NULL;
1220 GetMagickToken(q,(const char **) NULL,token);
1223 GetMagickToken(q,&q,token);
1224 GetMagickToken(q,&q,token);
1230 if (LocaleCompare((char *) keyword,"encoding") == 0)
1232 type_info->encoding=ConstantString(token);
1240 if (LocaleCompare((char *) keyword,"face") == 0)
1242 type_info->face=StringToUnsignedLong(token);
1245 if (LocaleCompare((char *) keyword,"family") == 0)
1247 type_info->family=ConstantString(token);
1250 if (LocaleCompare((char *) keyword,"format") == 0)
1252 type_info->format=ConstantString(token);
1255 if (LocaleCompare((char *) keyword,"foundry") == 0)
1257 type_info->foundry=ConstantString(token);
1260 if (LocaleCompare((char *) keyword,"fullname") == 0)
1262 type_info->description=ConstantString(token);
1270 if (LocaleCompare((char *) keyword,"glyphs") == 0)
1272 if (SetTypeNodePath(filename,font_path,token,&type_info->glyphs) ==
1274 type_info=(TypeInfo *) DestroyTypeNode(type_info);
1282 if (LocaleCompare((char *) keyword,"metrics") == 0)
1284 if (SetTypeNodePath(filename,font_path,token,&type_info->metrics) ==
1286 type_info=(TypeInfo *) DestroyTypeNode(type_info);
1294 if (LocaleCompare((char *) keyword,"name") == 0)
1296 type_info->name=ConstantString(token);
1304 if (LocaleCompare((char *) keyword,"stealth") == 0)
1306 type_info->stealth=IsStringTrue(token);
1309 if (LocaleCompare((char *) keyword,"stretch") == 0)
1311 type_info->stretch=(StretchType) ParseCommandOption(
1312 MagickStretchOptions,MagickFalse,token);
1315 if (LocaleCompare((char *) keyword,"style") == 0)
1317 type_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
1326 if (LocaleCompare((char *) keyword,"weight") == 0)
1328 type_info->weight=StringToUnsignedLong(token);
1329 if (LocaleCompare(token,"bold") == 0)
1330 type_info->weight=700;
1331 if (LocaleCompare(token,"normal") == 0)
1332 type_info->weight=400;
1341 token=(char *) RelinquishMagickMemory(token);
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1350 + T y p e C o m p o n e n t G e n e s i s %
1354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1356 % TypeComponentGenesis() instantiates the type component.
1358 % The format of the TypeComponentGenesis method is:
1360 % MagickBooleanType TypeComponentGenesis(void)
1363 MagickPrivate MagickBooleanType TypeComponentGenesis(void)
1365 if (type_semaphore == (SemaphoreInfo *) NULL)
1366 type_semaphore=AcquireSemaphoreInfo();
1371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375 + T y p e C o m p o n e n t T e r m i n u s %
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % TypeComponentTerminus() destroy type component.
1383 % The format of the TypeComponentTerminus method is:
1385 % void TypeComponentTerminus(void)
1388 MagickPrivate void TypeComponentTerminus(void)
1390 if (type_semaphore == (SemaphoreInfo *) NULL)
1391 ActivateSemaphoreInfo(&type_semaphore);
1392 LockSemaphoreInfo(type_semaphore);
1393 if (type_cache != (SplayTreeInfo *) NULL)
1394 type_cache=DestroySplayTree(type_cache);
1395 UnlockSemaphoreInfo(type_semaphore);
1396 RelinquishSemaphoreInfo(&type_semaphore);