### FcMatrix Transformation Examples Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Provides examples of scaling and rotating a font using FcMatrix. ```APIDOC ## FcMatrix Transformations ### Example: Scaling ```c FcMatrix scale; FcMatrixInit(&scale); FcMatrixScale(&scale, 1.0, 0.5); /* Scale vertically by 50% */ ``` ### Example: Rotation ```c FcMatrix rotate; FcMatrixInit(&rotate); FcMatrixRotate(&rotate, 0.707, 0.707); /* Rotate 45 degrees */ ``` ``` -------------------------------- ### Fontconfig Test Query Example Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md An example of a query pattern for Fontconfig tests, specifying font family, weight, and size. ```json { "query": { "family": "Noto Sans", "weight": "bold", "size": 12.0 } } ``` -------------------------------- ### Fontconfig Test Result Font Set Example (List/Sort) Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md Example of an expected font set result for Fontconfig tests using 'list', 'sort', or 'sort_all' methods. Verifies the number and properties of returned fonts. ```json { "result_fs": [ { "family": "Noto Sans", "file": "/path/to/NotoSans-Regular.ttf" }, { "family": "Noto Sans", "file": "/path/to/NotoSans-Bold.ttf" } ] } ``` -------------------------------- ### Iterating Through FcStrSet Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Example demonstrating how to create an iterator for an FcStrSet and traverse its string elements. Remember to free the iterator when done. ```c FcStrList *list = FcStrListCreate(strset); FcChar8 *str; while ((str = FcStrListNext(list))) { printf("%s\n", (char *)str); } FcStrListDone(list); ``` -------------------------------- ### Example of FcBlanksDestroy Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Shows the typical usage pattern of creating a blanks object, using it for font scanning operations, and then explicitly destroying it to release resources. ```c FcBlanks *blanks = FcBlanksCreate(); /* Use blanks */ FcBlanksDestroy(blanks); ``` -------------------------------- ### Initialize Fontconfig and Find a Font Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/README.md A minimal example demonstrating how to initialize Fontconfig, create a font pattern, find the best matching font, and clean up resources. Ensure FcInit() is called before any other Fontconfig functions and FcFini() is called at the end. ```c #include #include int main() { /* Initialize fontconfig */ if (!FcInit()) { fprintf(stderr, "Failed to init fontconfig\n"); return 1; } /* Create a pattern for "sans-serif at 12pt" */ FcPattern *pattern = FcPatternCreate(); FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)"sans-serif"); FcPatternAddDouble(pattern, FC_SIZE, 12); /* Find best matching font */ FcResult result; FcPattern *font = FcFontMatch(NULL, pattern, &result); if (font) { FcChar8 *file; int index; /* Get matched font file and index */ if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch && FcPatternGetInteger(font, FC_INDEX, 0, &index) == FcResultMatch) { printf("Font: %s (index %d)\n", (char *)file, index); } FcPatternDestroy(font); } FcPatternDestroy(pattern); FcFini(); return 0; } ``` -------------------------------- ### Fontconfig Test Result Example (Match/Pattern) Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md Example of an expected result pattern for Fontconfig tests using 'match' or 'pattern' methods. Verifies specific font properties. ```json { "result": { "family": "Noto Sans", "file": "/path/to/NotoSans-Bold.ttf", "weight": 200 } } ``` -------------------------------- ### Iterating Through FcFontSet Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Example demonstrating how to iterate through the fonts within an FcFontSet. This pattern is useful for processing each font pattern in a collection. ```c FcFontSet *fontset = /* ... */; for (int i = 0; i < fontset->nfont; i++) { FcPattern *font = fontset->fonts[i]; /* Process font */ } ``` -------------------------------- ### Add String Value to Pattern with FcPatternCreate Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md This example demonstrates creating a pattern and then adding a string value for the FC_FAMILY property. ```c FcPattern *pattern = FcPatternCreate(); FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)"DejaVu Sans"); FcPatternAddInteger(pattern, FC_SIZE, 12); ``` -------------------------------- ### Example of FcBlanksCreate and FcBlanksAdd Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Demonstrates creating a blanks object and adding specific characters, such as the NULL character and zero-width space, to be ignored during font scanning. Handles potential memory allocation failures. ```c FcBlanks *blanks = FcBlanksCreate(); if (!blanks) { fprintf(stderr, "Memory allocation failed\n"); return; } FcBlanksAdd(blanks, 0x0000); /* NULL character */ FcBlanksAdd(blanks, 0x200B); /* Zero-width space */ ``` -------------------------------- ### Example: Load, Use, and Unload Font Cache Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/10-fonts-cache.md Demonstrates the typical workflow of loading a font cache, performing operations with it (represented by a comment), and then unloading it to free resources. Ensure the cache is unloaded to prevent memory leaks. ```c FcCache *cache = FcDirCacheRead((FcChar8 *)"/usr/share/fonts", FcFalse, NULL); if (cache) { /* Use cache data */ FcDirCacheUnload(cache); } ``` -------------------------------- ### Fontconfig Test Comment Example Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md Example of using the optional '$comment' field in a Fontconfig test object for documentation purposes. ```json { "$comment": "This test verifies that bold synthesis works correctly" } ``` -------------------------------- ### Install Custom Font Filter Function Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/09-substitution.md Installs a custom filter function to exclude specific fonts during discovery. The filter function receives font patterns and user data, returning FcTrue to keep a font. ```c FcBool exclude_bitmap_fonts(const FcPattern *font, void *user_data) { FcBool scalable; /* Only keep scalable fonts */ if (FcPatternGetBool(font, FC_SCALABLE, 0, &scalable) == FcResultMatch) { return scalable; } return FcFalse; } FcConfig *config = FcConfigGetCurrent(); FcConfigSetFontSetFilter(config, exclude_bitmap_fonts, NULL, NULL); FcConfigBuildFonts(config); ``` -------------------------------- ### Example FcFilterFontSetFunc Implementation Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/09-substitution.md An example implementation of FcFilterFontSetFunc that keeps only sans-serif fonts. It retrieves the font family and checks if it contains 'Sans'. ```c FcBool keep_sans_serif(const FcPattern *font, void *user_data) { FcChar8 *family = NULL; FcPatternGetString(font, FC_FAMILY, 0, &family); /* Keep only sans-serif fonts */ if (family && FcStrStr(family, (FcChar8 *)"Sans")) { return FcTrue; } return FcFalse; } ``` -------------------------------- ### List All Fonts with Specific Properties Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/README.md This example demonstrates how to retrieve a list of all available fonts that match certain criteria. FcObjectSetBuild is used to specify which font properties to retrieve, and FcFontList returns a FcFontSet containing the matching fonts. ```c FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_FILE, NULL); FcFontSet *fs = FcFontList(NULL, NULL, os); for (int i = 0; i < fs->nfont; i++) { FcChar8 *family; FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family); printf("%s\n", (char *)family); } FcFontSetDestroy(fs); FcObjectSetDestroy(os); ``` -------------------------------- ### Get Loaded Configuration Files with FcConfigGetConfigFiles Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns a list of all configuration files that were parsed and loaded into the configuration. Remember to free the returned list with FcStrListDone. ```c FcConfig *config = FcConfigGetCurrent(); FcStrList *files = FcConfigGetConfigFiles(config); FcChar8 *file; while ((file = FcStrListNext(files))) { printf("Config file: %s\n", (char *)file); } FcStrListDone(files); ``` -------------------------------- ### Example of FcConfigGetBlanks Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Shows how to obtain the current Fontconfig configuration and then retrieve its associated blanks set. It then checks if the NULL character is present in this set, indicating it's ignored during font scanning. ```c FcConfig *config = FcConfigGetCurrent(); FcBlanks *blanks = FcConfigGetBlanks(config); if (blanks && FcBlanksIsMember(blanks, 0x0000)) { printf("NULL character is ignored during scanning\n"); } ``` -------------------------------- ### Example: Copy and Destroy Font Set from Cache Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/10-fonts-cache.md Illustrates how to obtain a font set from a cache, print the number of fonts it contains, and then properly destroy the copied font set to release memory. Always ensure the font set is destroyed after use. ```c FcCache *cache = FcDirCacheRead((FcChar8 *)"/usr/share/fonts", FcFalse, NULL); if (cache) { FcFontSet *fonts = FcCacheCopySet(cache); if (fonts) { printf("Cache contains %d fonts\n", fonts->nfont); FcFontSetDestroy(fonts); } FcDirCacheUnload(cache); } ``` -------------------------------- ### Get Configuration Directories with FcConfigGetConfigDirs Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns a list of configuration directories from which configuration files are loaded. These are the directories where fontconfig looks for .conf files. ```c FcConfig *config = FcConfigGetCurrent(); FcStrList *dirs = FcConfigGetConfigDirs(config); FcChar8 *dir; while ((dir = FcStrListNext(dirs))) { printf("Config directory: %s\n", (char *)dir); } FcStrListDone(dirs); ``` -------------------------------- ### Create Fontconfig Configuration Instance Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Creates a new, empty fontconfig configuration instance. Useful for isolated configurations or custom setups. Ensure to check for memory allocation failure. ```c FcConfig *config = FcConfigCreate(); if (!config) { fprintf(stderr, "Memory allocation failed\n"); return; } /* Load custom configuration */ FcConfigParseAndLoad(config, (FcChar8 *)"/etc/fontconfig/custom.conf", FcTrue); FcConfigDestroy(config); ``` -------------------------------- ### Example of FcBlanksIsMember Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Illustrates how to check if specific characters, like the zero-width space, are considered blank and if a regular character, like 'A', is not. This is useful for verifying the contents of a blanks set. ```c FcBlanks *blanks = FcBlanksCreate(); FcBlanksAdd(blanks, 0x200B); /* Zero-width space */ if (FcBlanksIsMember(blanks, 0x200B)) { printf("Zero-width space is blank\n"); } if (!FcBlanksIsMember(blanks, 0x0041)) { printf("A is not blank\n"); } ``` -------------------------------- ### Get Font Directories with FcConfigGetFontDirs Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns a list of font directories from the configuration. The list represents all directories that will be scanned for fonts. Remember to free the returned list with FcStrListDone. ```c FcConfig *config = FcConfigGetCurrent(); FcStrList *dirs = FcConfigGetFontDirs(config); FcChar8 *dir; while ((dir = FcStrListNext(dirs))) { printf("Font directory: %s\n", (char *)dir); } FcStrListDone(dirs); ``` -------------------------------- ### Example of FcBlanksAdd with common blank characters Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Demonstrates adding several common characters, including NULL, space, and various zero-width characters, to a blanks object to ensure they are ignored during font scanning. ```c FcBlanks *blanks = FcBlanksCreate(); /* Skip common blank characters */ FcBlanksAdd(blanks, 0x0000); /* NULL */ FcBlanksAdd(blanks, 0x0020); /* Space */ FcBlanksAdd(blanks, 0x200B); /* Zero-width space */ FcBlanksAdd(blanks, 0x200C); /* Zero-width non-joiner */ ``` -------------------------------- ### Get Cache Directories with FcConfigGetCacheDirs Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns a list of all directories where fontconfig stores cache files. Remember to free the returned list with FcStrListDone. ```c FcConfig *config = FcConfigGetCurrent(); FcStrList *dirs = FcConfigGetCacheDirs(config); FcChar8 *dir; while ((dir = FcStrListNext(dirs))) { printf("Cache directory: %s\n", (char *)dir); } FcStrListDone(dirs); ``` -------------------------------- ### Iterate and Print Font Names from FcFontSet Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/08-fontset.md Example of how to list all fonts in a font set and print their family names. Ensure to check for FcResultMatch when retrieving string properties. ```c FcFontSet *fontset = FcFontList(NULL, NULL, NULL); if (fontset) { for (int i = 0; i < fontset->nfont; i++) { FcPattern *font = fontset->fonts[i]; FcChar8 *family; if (FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch) { printf("Font: %s\n", (char *)family); } } } ``` -------------------------------- ### FcInitReinitialize Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Reinitializes the global fontconfig configuration and font database, discarding all cached state. Useful for detecting newly installed fonts or reloading configuration changes without restarting the application. ```APIDOC ## FcInitReinitialize ### Description Reinitializes the global fontconfig configuration and font database, discarding all cached state. Useful for detecting newly installed fonts or reloading configuration changes without restarting the application. ### Method `FcBool FcInitReinitialize(void)` ### Parameters No parameters. ### Return Type `FcBool` (FcTrue on success, FcFalse on failure) ### Example ```c /* After fonts are installed or configuration changed */ if (!FcInitReinitialize()) { fprintf(stderr, "Failed to reinitialize\n"); } ``` ``` -------------------------------- ### Resolve Configuration Filename Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Resolves a configuration file path, expanding '~' and checking system directories. Pass NULL to get the default configuration file path. The returned path must be freed with FcStrFree. ```c FcChar8 *FcConfigFilename(const FcChar8 *url) ``` ```c FcChar8 *path = FcConfigFilename((FcChar8 *)"~/.config/fontconfig/fonts.conf"); printf("Config file: %s\n", (char *)path); FcStrFree(path); ``` -------------------------------- ### FcConfigCreate Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Creates a new, empty fontconfig configuration instance without loading any configuration files or fonts. Useful for creating isolated configurations or for advanced applications that need custom setup. ```APIDOC ## FcConfigCreate ### Description Creates a new, empty fontconfig configuration instance without loading any configuration files or fonts. Useful for creating isolated configurations or for advanced applications that need custom setup. ### Method C Function ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c FcConfig *config = FcConfigCreate(); if (!config) { fprintf(stderr, "Memory allocation failed\n"); return; } /* Load custom configuration */ FcConfigParseAndLoad(config, (FcChar8 *)"/etc/fontconfig/custom.conf", FcTrue); FcConfigDestroy(config); ``` ### Response #### Success Response `FcConfig *` (pointer to newly allocated configuration, or NULL on memory failure) #### Response Example (See Request Example for usage) ``` -------------------------------- ### Get Font Set from Configuration Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Retrieves a font set from the configuration. The set parameter determines whether to return system or application fonts. The returned font set is owned by the config and should not be freed. ```c FcFontSet *FcConfigGetFonts(FcConfig *config, FcSetName set) ``` ```c FcConfig *config = FcConfigGetCurrent(); FcFontSet *fonts = FcConfigGetFonts(config, FcSetSystem); printf("Found %d system fonts\n", fonts->nfont); ``` -------------------------------- ### FcInit Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Initializes the default fontconfig configuration and font database. This function should typically be called once at application startup. ```APIDOC ## FcInit ### Description Initializes the default fontconfig configuration and font database. Creates and loads the default configuration file if it hasn't been loaded yet. This is typically called once at application startup. ### Method `FcBool FcInit(void)` ### Parameters No parameters. ### Return Type `FcBool` (FcTrue on success, FcFalse on failure) ### Example ```c #include if (!FcInit()) { fprintf(stderr, "Failed to initialize Fontconfig\n"); exit(1); } ``` ``` -------------------------------- ### FcInitLoadConfigAndFonts Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Loads the default configuration and builds the font database in one step. Returns a fully initialized FcConfig instance ready for font matching. ```APIDOC ## FcInitLoadConfigAndFonts ### Description Loads the default configuration and builds the font database in one step. Returns a fully initialized FcConfig instance ready for font matching. ### Method `FcConfig *FcInitLoadConfigAndFonts(void)` ### Parameters No parameters. ### Return Type `FcConfig *` (pointer to newly allocated and initialized configuration, or NULL on failure) ### Example ```c FcConfig *config = FcInitLoadConfigAndFonts(); if (!config) { fprintf(stderr, "Failed to initialize\n"); return; } FcPattern *pattern = FcPatternCreate(); /* Configure pattern and match fonts */ FcConfigDestroy(config); ``` ``` -------------------------------- ### Scale FcMatrix Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Applies scaling to an existing FcMatrix. For example, scaling vertically by 50% involves modifying the 'yy' component. ```c FcMatrix scale; FcMatrixInit(&scale); FcMatrixScale(&scale, 1.0, 0.5); /* Scale vertically by 50% */ ``` -------------------------------- ### Initialize Fontconfig Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Initializes the default fontconfig configuration and font database. Call this once at application startup. ```c #include if (!FcInit()) { fprintf(stderr, "Failed to initialize Fontconfig\n"); exit(1); } ``` -------------------------------- ### Typical Fontconfig Workflow Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/00-START-HERE.md This C code snippet demonstrates the standard workflow for using the Fontconfig library. It covers creating a request pattern, matching it against system fonts, preparing for rendering, and extracting font file information. Remember to clean up allocated patterns. ```c // 1. Create a request pattern FcPattern *request = FcPatternCreate(); FcPatternAddString(request, FC_FAMILY, "sans-serif"); FcPatternAddDouble(request, FC_SIZE, 12); // 2. Match it against available fonts FcResult result; FcPattern *matched = FcFontMatch(NULL, request, &result); // 3. Prepare for rendering FcPattern *rendered = FcFontRenderPrepare(NULL, request, matched); // 4. Extract needed information FcChar8 *file; int index; FcPatternGetString(rendered, FC_FILE, 0, &file); FcPatternGetInteger(rendered, FC_INDEX, 0, &index); // 5. Clean up FcPatternDestroy(rendered); FcPatternDestroy(matched); FcPatternDestroy(request); ``` -------------------------------- ### Get Boolean Value from Fontconfig Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md A convenience function to retrieve a boolean value from a pattern. It returns FcResultMatch on success. ```c FcResult FcPatternGetBool(const FcPattern *p, const char *object, int n, FcBool *b) ``` ```c FcBool antialias; if (FcPatternGetBool(pattern, FC_ANTIALIAS, 0, &antialias) == FcResultMatch) { printf("Antialias: %s\n", antialias ? "true" : "false"); } ``` -------------------------------- ### Core Initialization Functions Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/README.md Functions for initializing the Fontconfig library, loading configuration, and managing library state. ```APIDOC ## Core Initialization ### Description Functions to initialize the Fontconfig library, load configuration files, and manage the library's global state. ### Functions - `FcInit()`: Initializes the library. - `FcInitLoadConfig()`: Initializes the library and loads the default configuration. - `FcInitLoadConfigAndFonts()`: Initializes the library, loads configuration, and builds the font database. - `FcInitReinitialize()`: Reinitializes the library, reloading configuration and fonts. - `FcInitBringUptoDate()`: Checks if configuration and fonts are up-to-date and reloads if necessary. - `FcFini()`: Shuts down the library and frees resources. - `FcGetVersion()`: Returns the library version. ``` -------------------------------- ### Get Double Value from Fontconfig Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md A convenience function to retrieve a double value from a pattern. It returns FcResultMatch on success. ```c FcResult FcPatternGetDouble(const FcPattern *p, const char *object, int n, double *d) ``` ```c double size; if (FcPatternGetDouble(pattern, FC_SIZE, 0, &size) == FcResultMatch) { printf("Size: %f\n", size); } ``` -------------------------------- ### FcStrSetAddFilename: Add Filename to Set Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/07-strings.md Adds a filename to a string set, automatically expanding the '~' character to the user's home directory. Returns FcTrue on success. ```c FcBool FcStrSetAddFilename(FcStrSet *set, const FcChar8 *s) ``` ```c FcStrSet *set = FcStrSetCreate(); FcStrSetAddFilename(set, (FcChar8 *)"~/.fonts"); /* Path is expanded to user's home directory */ ``` -------------------------------- ### Get Integer Value from Fontconfig Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md A convenience function to retrieve an integer value from a pattern. It returns FcResultMatch on success. ```c FcResult FcPatternGetInteger(const FcPattern *p, const char *object, int n, int *i) ``` ```c int weight; if (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &weight) == FcResultMatch) { printf("Weight: %d\n", weight); } ``` -------------------------------- ### Substitution and Configuration Loading Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/README.md Functions for applying substitution rules from configuration files and setting default substitutions. ```APIDOC ## Substitution and Configuration ### Description Functions that apply font substitution rules defined in configuration files and apply default substitutions for rendering features like antialiasing and hinting. ### Functions - `FcConfigSubstitute()`: Applies font substitution rules from the configuration to a pattern. - `FcConfigSubstituteWithPat()`: Applies font substitution rules, including pattern-based rules. - `FcDefaultSubstitute()`: Applies default substitutions for rendering (e.g., antialiasing, hinting). - `FcConfigParseAndLoad()`: Parses and loads configuration files from the system. - `FcConfigParseAndLoadFromMemory()`: Parses and loads configuration from a memory buffer. - `FcConfigSetFontSetFilter()`: Sets a filter function to modify the font set during discovery. ``` -------------------------------- ### Get String Value from Fontconfig Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md A convenience function to retrieve a string value from a pattern. It returns FcResultMatch on success. ```c FcResult FcPatternGetString(const FcPattern *p, const char *object, int n, FcChar8 **s) ``` ```c FcChar8 *family; if (FcPatternGetString(pattern, FC_FAMILY, 0, &family) == FcResultMatch) { printf("Family: %s\n", (char *)family); } ``` -------------------------------- ### Get Original File Path Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Returns the path of the original file. This is primarily useful for logging or error reporting purposes. ```c /* FcAtomicOrigFile(atomic) returns the original file path */ ``` -------------------------------- ### Rotate FcMatrix Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Applies rotation to an existing FcMatrix. The rotation is defined by cosine and sine values, for example, rotating by 45 degrees. ```c FcMatrix rotate; FcMatrixInit(&rotate); FcMatrixRotate(&rotate, 0.707, 0.707); /* Rotate 45 degrees */ ``` -------------------------------- ### Create an Empty Font Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md Use FcPatternCreate to initialize a new, empty pattern. Ensure to check for memory allocation failures. ```c FcPattern *pattern = FcPatternCreate(); if (!pattern) { fprintf(stderr, "Memory allocation failed\n"); return; } ``` -------------------------------- ### Fontconfig Test Configuration: Prefer Application Font Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md Example of configuring a Fontconfig test to prefer application fonts over system fonts. ```json { "config": { "prefer_app_font": true } } ``` -------------------------------- ### Load Fontconfig Configuration and Fonts Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Loads the default configuration and builds the font database in one step. Returns a fully initialized FcConfig instance. ```c FcConfig *config = FcInitLoadConfigAndFonts(); if (!config) { fprintf(stderr, "Failed to initialize\n"); return; } FcPattern *pattern = FcPatternCreate(); /* Configure pattern and match fonts */ FcConfigDestroy(config); ``` -------------------------------- ### FcConfigSetFontSetFilter Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/09-substitution.md Installs a custom filter function that will be called for each font during font discovery. Allows applications to exclude certain fonts from the database. ```APIDOC ## FcConfigSetFontSetFilter ### Description Installs a custom filter function that will be called for each font during font discovery. Allows applications to exclude certain fonts from the database. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (C function) ### Endpoint None (C function) ### Parameters - **config** (`FcConfig *`) - Required - Configuration to modify - **filter_func** (`FcFilterFontSetFunc`) - Required - Callback function, return FcTrue to keep font - **destroy_data_func** (`FcDestroyFunc`) - Required - Cleanup function for user_data - **user_data** (`void *`) - Required - Data passed to filter_func ### Return Type `FcConfig *` (same config, or NULL on error) ### Example ```c FcBool exclude_bitmap_fonts(const FcPattern *font, void *user_data) { FcBool scalable; /* Only keep scalable fonts */ if (FcPatternGetBool(font, FC_SCALABLE, 0, &scalable) == FcResultMatch) { return scalable; } return FcFalse; } FcConfig *config = FcConfigGetCurrent(); FcConfigSetFontSetFilter(config, exclude_bitmap_fonts, NULL, NULL); FcConfigBuildFonts(config); ``` ``` -------------------------------- ### Get Rescan Interval with FcConfigGetRescanInterval Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns the font directory rescan interval in seconds. A value of 0 disables automatic rescanning. ```c FcConfig *config = FcConfigGetCurrent(); int interval = FcConfigGetRescanInterval(config); printf("Rescan interval: %d seconds\n", interval); ``` -------------------------------- ### Get Current Fontconfig Configuration Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Retrieves the current global default fontconfig configuration. This is used by default matching and querying functions. ```c FcConfig *config = FcConfigGetCurrent(); FcFontSet *fonts = FcConfigGetFonts(config, FcSetSystem); ``` -------------------------------- ### FcStrSetCreate Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/07-strings.md Creates and returns a new, empty string set. Returns NULL if memory allocation fails. ```APIDOC ## FcStrSetCreate ### Description Creates a new, empty string set. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (C function) ### Endpoint None (C function) ### Parameters - **—** (`—`) - — - No parameters ### Return Type `FcStrSet *` (newly allocated empty set, or NULL on memory failure) ### Example ```c FcStrSet *set = FcStrSetCreate(); if (!set) { fprintf(stderr, "Memory allocation failed\n"); return; } FcStrSetAdd(set, (FcChar8 *)"/usr/share/fonts"); ``` ``` -------------------------------- ### Get Double-Precision Range Values Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/14-range.md Retrieves the minimum and maximum values from a double-precision range. Returns FcTrue on success and FcFalse on error. ```c FcRange *range = FcRangeCreateDouble(10.0, 20.0); double min, max; if (FcRangeGetDouble(range, &min, &max)) { printf("Range: %.1f to %.1f\n", min, max); /* Prints "Range: 10.0 to 20.0" */ } FcRangeDestroy(range); ``` -------------------------------- ### Create an empty language set Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/06-language.md Use FcLangSetCreate to initialize a new, empty language set. Check the return value for memory allocation failures. ```c FcLangSet *langs = FcLangSetCreate(); if (!langs) { fprintf(stderr, "Memory allocation failed\n"); return; } FcLangSetAdd(langs, (FcChar8 *)"en"); FcLangSetAdd(langs, (FcChar8 *)"de"); ``` -------------------------------- ### Get Value from Fontconfig Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/03-patterns.md Retrieves a value from a pattern. Use the id parameter to select a specific value if multiple exist for the same property. ```c FcResult FcPatternGet(const FcPattern *p, const char *object, int id, FcValue *v) ``` ```c FcValue v; FcResult result = FcPatternGet(pattern, FC_FAMILY, 0, &v); if (result == FcResultMatch && v.type == FcTypeString) { printf("Family: %s\n", (char *)v.u.s); } ``` -------------------------------- ### FcConfigGetConfigFiles Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Returns a list of all configuration files that were parsed and loaded into the configuration. ```APIDOC ## FcConfigGetConfigFiles ### Description Returns a list of all configuration files that were parsed and loaded into the configuration. ### Method `FcStrList *FcConfigGetConfigFiles(FcConfig *config)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c FcConfig *config = FcConfigGetCurrent(); FcStrList *files = FcConfigGetConfigFiles(config); FcChar8 *file; while ((file = FcStrListNext(files))) { printf("Config file: %s\n", (char *)file); } FcStrListDone(files); ``` ### Response #### Success Response (FcStrList *) Returns a list of loaded configuration file paths. #### Response Example `FcStrList *` representing a list of configuration file paths. ``` -------------------------------- ### Get Fontconfig Version Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Returns the compiled Fontconfig version number as an integer. The version is encoded as MAJOR*10000 + MINOR*100 + REVISION. ```c int version = FcGetVersion(); int major = version / 10000; int minor = (version % 10000) / 100; int revision = version % 100; printf("Fontconfig %d.%d.%d\n", major, minor, revision); ``` -------------------------------- ### Build FcObjectSet with Variadic Arguments Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/08-fontset.md FcObjectSetBuild creates and populates an object set in one step using a NULL-terminated list of property names. This is a convenient way to initialize an object set with multiple properties. ```c FcObjectSet *os = FcObjectSetBuild( FC_FAMILY, FC_STYLE, FC_FILE, FC_WEIGHT, NULL /* Must terminate with NULL */ ); if (os) { FcFontSet *fonts = FcFontList(NULL, NULL, os); /* ... */ FcObjectSetDestroy(os); } ``` -------------------------------- ### Get Constant Metadata Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/13-names-parsing.md Retrieves metadata for a given constant name string, including its integer value and associated property object name. ```c const FcConstant *const_info = FcNameGetConstant((FcChar8 *)"bold"); if (const_info) { printf("Value: %d\n", const_info->value); printf("Object: %s\n", const_info->object); /* Likely "weight" */ } ``` -------------------------------- ### Apply Substitution Rules to a Pattern Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/09-substitution.md Applies all substitution rules from the configuration to a pattern. Rules are applied in two phases: pattern matching rules (before match) and font rules (after match). Use NULL for the config to use the current configuration. ```c FcPattern *pattern = FcPatternCreate(); FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)"sans-serif"); FcPatternAddDouble(pattern, FC_SIZE, 12); /* Apply pattern matching rules */ FcConfigSubstitute(NULL, pattern, FcMatchPattern); /* Now pattern has been modified with user preferences */ FcChar8 *substituted_family; if (FcPatternGetString(pattern, FC_FAMILY, 0, &substituted_family) == FcResultMatch) { printf("Substituted family: %s\n", (char *)substituted_family); } FcPatternDestroy(pattern); ``` -------------------------------- ### Initialization Functions Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/INDEX.md Functions for initializing and cleaning up the Fontconfig library, as well as querying its version. ```APIDOC ## Initialization API ### Description Functions for initializing and cleaning up the Fontconfig library, as well as querying its version. ### Functions - `FcInit()`: Initialize fontconfig. - `FcInitLoadConfig()`: Load configuration only. - `FcInitLoadConfigAndFonts()`: Load everything. - `FcInitReinitialize()`: Force reinitialization. - `FcInitBringUptoDate()`: Update font database. - `FcFini()`: Cleanup. - `FcGetVersion()`: Version query. ``` -------------------------------- ### Get Next String from FcStrList Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/07-strings.md Retrieves the next string from the iterator. Returns NULL when all strings have been enumerated. This function is typically used within a loop. ```c FcChar8 *FcStrListNext(FcStrList *list) ``` -------------------------------- ### Get System Root Directory Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Retrieves the system root directory path used for chrooted environments. Returns NULL if no system root is configured. ```c const FcChar8 *FcConfigGetSysRoot(const FcConfig *config) ``` -------------------------------- ### Build Font Database with FcConfigBuildFonts Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Scans font directories and builds the font database for the configuration. This is typically called automatically during configuration initialization but can be called explicitly to rebuild the database. ```c FcConfig *config = FcConfigCreate(); FcConfigParseAndLoad(config, (FcChar8 *)"/etc/fonts/fonts.conf", FcTrue); if (FcConfigBuildFonts(config)) { /* Font database built */ } ``` -------------------------------- ### Get All Known Languages Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/06-language.md Retrieves a set containing all language tags known to the fontconfig library. The returned set must be destroyed using FcStrSetDestroy. ```c FcStrSet *allLangs = FcGetLangs(); if (allLangs) { printf("Fontconfig knows about %d languages\n", allLangs->num); FcStrSetDestroy(allLangs); } ``` -------------------------------- ### Get Character Set for Language Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/06-language.md Retrieves the character set required to display a specific language. This can be used to check if a font supports a given language. ```c /* Get required characters for Greek */ const FcCharSet *greek_charset = FcLangGetCharSet((FcChar8 *)"el"); if (greek_charset) { printf("Greek requires %d characters\n", FcCharSetCount(greek_charset)); /* Check if a font covers Greek */ FcPattern *font = /* ... */; FcCharSet *font_charset; if (FcPatternGetCharSet(font, FC_CHARSET, 0, &font_charset) == FcResultMatch) { if (FcCharSetIsSubset(greek_charset, font_charset)) { printf("Font fully supports Greek\n"); } } } ``` -------------------------------- ### Configuration Management Functions Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/README.md Functions for creating, destroying, and managing configuration instances, including font directories and substitution rules. ```APIDOC ## Configuration Management ### Description Functions for managing Fontconfig configuration instances, including setting the current configuration, accessing font directories, and building font databases. ### Functions - `FcConfigCreate()`: Creates a new configuration instance. - `FcConfigDestroy()`: Destroys a configuration instance. - `FcConfigReference()`: Increments the reference count of a configuration instance. - `FcConfigSetCurrent()`: Sets the current configuration instance. - `FcConfigGetCurrent()`: Gets the current configuration instance. - `FcConfigUptoDate()`: Checks if the current configuration is up-to-date. - `FcConfigGetFontDirs()`: Gets the list of font directories in the configuration. - `FcConfigGetFonts()`: Gets the font set associated with the configuration. - `FcConfigBuildFonts()`: Builds the font database for the configuration. - `FcConfigParseAndLoad()`: Parses and loads configuration files. - `FcConfigSetSysRoot()`: Sets the system root directory for configuration loading. ``` -------------------------------- ### Get Directory Path from Cache Object Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/10-fonts-cache.md Retrieves the directory path associated with a given font cache object. The returned pointer should not be freed by the caller. ```c const FcChar8 *FcCacheDir(const FcCache *c) ``` -------------------------------- ### FcMatrix Structure and Initialization Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Defines the FcMatrix structure for 2D transformations and demonstrates its initialization. ```APIDOC ## FcMatrix ### Description A 2D transformation matrix for font rotation, scaling, and skewing. Uses column-major order. ### Fields - `xx` (double) - horizontal scaling - `xy` (double) - horizontal skew - `yx` (double) - vertical skew - `yy` (double) - vertical scaling ### Initialization ```c typedef struct _FcMatrix { double xx, xy, yx, yy; } FcMatrix; FcMatrix m; FcMatrixInit(&m); /* Sets m.xx = m.yy = 1, m.xy = m.yx = 0 */ ``` ``` -------------------------------- ### Update Fontconfig Database Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/01-initialization.md Updates the font database to include newly installed fonts. Rescans font directories if they have been modified. Less intensive than full reinitialization. ```c /* Check for newly installed fonts */ if (FcInitBringUptoDate()) { /* Database is up to date or was refreshed */ } ``` -------------------------------- ### Get Next Page of Characters in CharSet Iteration Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/05-charset.md Continues iteration to the next page of characters in a character set. This function is called after FcCharSetFirstPage within a loop. ```c FcChar32 FcCharSetNextPage(const FcCharSet *a, FcChar32 map[FC_CHARSET_MAP_SIZE], FcChar32 *next) ``` -------------------------------- ### Initialize FcMatrix Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/types.md Initializes an FcMatrix to an identity matrix (xx=1, yy=1, xy=0, yx=0). Use this before applying transformations. ```c FcMatrix m; FcMatrixInit(&m); /* Sets m.xx = m.yy = 1, m.xy = m.yx = 0 */ ``` -------------------------------- ### FcLangSetGetLangs: Get Languages from Set Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/06-language.md Retrieves all individual language tags from a language set as a string set. Remember to free the returned string set after use. ```c FcStrSet *FcLangSetGetLangs(const FcLangSet *ls) ``` ```c FcLangSet *langs = /* ... */; FcStrSet *langstrs = FcLangSetGetLangs(langs); if (langstrs) { FcStrList *list = FcStrListCreate(langstrs); FcChar8 *lang; while ((lang = FcStrListNext(list))) { printf("Language: %s\n", (char *)lang); } FcStrListDone(list); FcStrSetDestroy(langstrs); } ``` -------------------------------- ### Get Constant for Specific Property Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/13-names-parsing.md Looks up a constant name and resolves it for a specific property, handling cases where constants might have different meanings depending on the context. ```c const FcConstant *const_info = FcNameGetConstantFor((FcChar8 *)"bold", FC_WEIGHT); if (const_info) { printf("Value: %d\n", const_info->value); printf("Object: %s\n", const_info->object); } ``` -------------------------------- ### Load Custom Fontconfig XML Configurations Source: https://github.com/fontconfig/fontconfig/blob/main/test/TEST-JSON-FORMAT.md Specifies a list of fontconfig XML configuration files to load. Use '%test%' as a placeholder for the test directory. ```json { "load_xml": [ "conf.d/48-guessfamily.conf", "conf.d/49-sansserif.conf", "%test%/test-custom.conf" ] } ``` -------------------------------- ### Check Fontconfig Configuration Up-to-Date Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/02-configuration.md Verifies if configuration files and font directories are current. Returns FcTrue if no changes are detected, FcFalse otherwise. ```c FcConfig *config = FcConfigGetCurrent(); if (!FcConfigUptoDate(config)) { FcInitReinitialize(); /* Reload configuration after changes */ } ``` -------------------------------- ### FcFontRenderPrepare Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/04-matching.md Prepares a matched font pattern for rendering by applying default values and rendering-specific substitutions like hinting and antialiasing. ```APIDOC ## FcFontRenderPrepare ### Description Prepares a matched font pattern for rendering. Applies default values and rendering-specific substitutions (like hinting, antialiasing) to create a complete pattern ready for FreeType. ### Signature ```c FcPattern *FcFontRenderPrepare(FcConfig *config, FcPattern *pat, FcPattern *font) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (`FcConfig *`) - Optional - Configuration (NULL uses current) - **pat** (`FcPattern *`) - Required - Original request pattern - **font** (`FcPattern *`) - Required - Matched font pattern from FcFontMatch ### Request Example ```c FcPattern *request = FcPatternCreate(); FcPatternAddString(request, FC_FAMILY, (FcChar8 *)"DejaVu Sans"); FcPatternAddDouble(request, FC_SIZE, 12); FcResult result; FcPattern *matched = FcFontMatch(NULL, request, &result); if (matched) { /* Prepare for rendering */ FcPattern *rendered = FcFontRenderPrepare(NULL, request, matched); if (rendered) { /* Now contains antialiasing, hinting, and other render settings */ FcChar8 *file; int index; if (FcPatternGetString(rendered, FC_FILE, 0, &file) == FcResultMatch && FcPatternGetInteger(rendered, FC_INDEX, 0, &index) == FcResultMatch) { /* Load font from file for rendering */ } FcPatternDestroy(rendered); } FcPatternDestroy(matched); } FcPatternDestroy(request); ``` ### Response #### Success Response (200) - **FcPattern *** - New pattern with rendering properties applied, or NULL on error #### Response Example None ### Throws None ### Source `src/fcmatch.c` ``` -------------------------------- ### Get Temporary File Path for Writing Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/12-blanks-atomic.md Returns the path of the temporary file that should be used for writing. All data must be written to this temporary file, not the original file directly. ```c FcAtomic *atomic = FcAtomicCreate((FcChar8 *)"/etc/my-config.conf"); FcChar8 *tmpfile = FcAtomicNewFile(atomic); if (tmpfile) { FILE *f = fopen((const char *)tmpfile, "w"); fprintf(f, "configuration data\n"); fclose(f); } ``` -------------------------------- ### FcFontRenderPrepare: Prepare Font for Rendering Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/04-matching.md Prepares a font pattern for rendering by applying default values and rendering-specific substitutions like hinting and antialiasing. This function creates a complete pattern suitable for FreeType. It takes the original request pattern and the matched font pattern as input. ```c FcPattern *FcFontRenderPrepare(FcConfig *config, FcPattern *pat, FcPattern *font) ``` ```c FcPattern *request = FcPatternCreate(); FcPatternAddString(request, FC_FAMILY, (FcChar8 *)"DejaVu Sans"); FcPatternAddDouble(request, FC_SIZE, 12); FcResult result; FcPattern *matched = FcFontMatch(NULL, request, &result); if (matched) { /* Prepare for rendering */ FcPattern *rendered = FcFontRenderPrepare(NULL, request, matched); if (rendered) { /* Now contains antialiasing, hinting, and other render settings */ FcChar8 *file; int index; if (FcPatternGetString(rendered, FC_FILE, 0, &file) == FcResultMatch && FcPatternGetInteger(rendered, FC_INDEX, 0, &index) == FcResultMatch) { /* Load font from file for rendering */ } FcPatternDestroy(rendered); } FcPatternDestroy(matched); } FcPatternDestroy(request); ``` -------------------------------- ### Find Substring within String Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/07-strings.md Finds the first occurrence of a substring within a larger string using a case-sensitive search. Returns a pointer to the start of the substring or NULL if not found. ```c const FcChar8 *FcStrStr(const FcChar8 *s1, const FcChar8 *s2); ``` -------------------------------- ### Create an Empty FcObjectSet Source: https://github.com/fontconfig/fontconfig/blob/main/_autodocs/08-fontset.md Use FcObjectSetCreate to initialize a new, empty object set. Check the return value for memory allocation success. This set can then be populated using FcObjectSetAdd. ```c FcObjectSet *os = FcObjectSetCreate(); if (!os) { fprintf(stderr, "Memory allocation failed"); return; } ```