]> granicus.if.org Git - libass/commitdiff
Export font provider interface
authorGrigori Goronzy <greg@chown.ath.cx>
Sat, 20 Aug 2011 16:19:25 +0000 (18:19 +0200)
committerGrigori Goronzy <greg@chown.ath.cx>
Fri, 10 Jul 2015 08:42:40 +0000 (10:42 +0200)
Add wrapper to the ASS_Renderer to create a font provider from
its internal font selector and shuffle some code around to export
everything that's needed for font providers to the public. Document
font provider functions.

libass/ass.h
libass/ass_fontselect.h
libass/ass_render_api.c
libass/ass_types.h
libass/libass.sym

index 774f344a39bef93e4c74f8ee6fdd949efc1f3e33..d6728eddbd1a8f0c7ae8869ad9052dc8873272b1 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
+ * Copyright (C) 2011 Grigori Goronzy <greg@chown.ath.cx>
  *
  * This file is part of libass.
  *
@@ -434,6 +435,40 @@ void ass_set_selective_style_override(ASS_Renderer *priv, ASS_Style *style);
  */
 int ass_fonts_update(ASS_Renderer *priv);
 
+/**
+ * \brief Create an empty font provider. A font provider can be used to
+ * provide additional fonts to libass.
+ * \param priv parent renderer
+ * \param funcs callback functions
+ * \param private data for provider callbacks
+ *
+ */
+ASS_FontProvider *
+ass_create_font_provider(ASS_Renderer *priv, ASS_FontProviderFuncs *funcs,
+                         void *data);
+
+/**
+ * \brief Add a font to a font provider.
+ * \param provider the font provider
+ * \param meta font metadata. See struct definition for more information.
+ * \param path absolute path to font, or NULL for memory-based fonts
+ * \param index index inside a font collection file
+ * \param data private data for font callbacks
+ * \return success
+ *
+ */
+int
+ass_font_provider_add_font(ASS_FontProvider *provider,
+                           ASS_FontProviderMetaData *meta, const char *path,
+                           unsigned int index, void *data);
+
+/**
+ * \brief Free font provider and associated fonts.
+ * \param provider the font provider
+ *
+ */
+void ass_font_provider_free(ASS_FontProvider *provider);
+
 /**
  * \brief Set hard cache limits.  Do not set, or set to zero, for reasonable
  * defaults.
index ec4c793f5d95408d4ed8b2c10a74d3c20067132e..59a447be37e579e678ea4b3750383b0f79f16255 100644 (file)
 
 typedef struct ass_shaper_font_data ASS_ShaperFontData;
 typedef struct font_selector ASS_FontSelector;
-typedef struct font_provider ASS_FontProvider;
 typedef struct font_info ASS_FontInfo;
 
 #include "ass_types.h"
 #include "ass.h"
 #include "ass_font.h"
 
-// get face data
-typedef void *(*GetFaceFunc)(void *, size_t *);
-
-// check for a glyph
-typedef int (*CheckGlyphFunc)(void *, uint32_t);
-
-// destroy font_info and related data
-typedef void (*DestroyFunc)(void *);
-typedef void (*DestroyProviderFunc)(void *);
-
-typedef struct font_provider_funcs {
-    GetFaceFunc     get_face;
-    CheckGlyphFunc  check_glyph;
-    DestroyFunc     destroy_font;
-    DestroyProviderFunc destroy_provider;
-} ASS_FontProviderFuncs;
-
-#define FONT_WEIGHT_LIGHT  300
-#define FONT_WEIGHT_MEDIUM 400
-#define FONT_WEIGHT_BOLD   700
-#define FONT_SLANT_NONE    0
-#define FONT_SLANT_ITALIC  100
-#define FONT_SLANT_OBLIQUE 110
-
-typedef struct font_provider_meta_data {
-    char *family;
-    char **fullnames;
-    int n_fullname;
-    int slant;
-    int weight;
-} ASS_FontProviderMetaData;
-
 ASS_FontSelector *
 ass_fontselect_init(ASS_Library *library,
                     FT_Library ftlibrary, const char *family,
@@ -76,9 +43,5 @@ void ass_fontselect_free(ASS_FontSelector *priv);
 // Font provider functions
 ASS_FontProvider *ass_font_provider_new(ASS_FontSelector *selector,
         ASS_FontProviderFuncs *funcs, void *data);
-int ass_font_provider_add_font(ASS_FontProvider *provider,
-        ASS_FontProviderMetaData *meta, const char *path, unsigned int index,
-        void *data);
-void ass_font_provider_free(ASS_FontProvider *provider);
 
 #endif                          /* LIBASS_FONTCONFIG_H */
index 5310060ec5a58814a6219ed70c5ae14ead5e9252..fe883bbef873c1802e544fc5531c8e7d8d5e7f64 100644 (file)
@@ -179,3 +179,10 @@ void ass_set_cache_limits(ASS_Renderer *render_priv, int glyph_max,
     render_priv->cache.bitmap_max_size = bitmap_max ? 1048576 * bitmap_max :
                                          BITMAP_CACHE_MAX_SIZE;
 }
+
+ASS_FontProvider *
+ass_create_font_provider(ASS_Renderer *priv, ASS_FontProviderFuncs *funcs,
+                         void *data)
+{
+    return ass_font_provider_new(priv->fontselect, funcs, data);
+}
index ccb0a0e6dc7a2747bc4581cfc6b3c50154a30252..01e73061ce217a217a20d426d72dbc4bd539c940 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
+ * Copyright (C) 2011 Grigori Goronzy <greg@chown.ath.cx>
  *
  * This file is part of libass.
  *
 #define HALIGN_CENTER 2
 #define HALIGN_RIGHT 3
 
+#define FONT_WEIGHT_LIGHT  300
+#define FONT_WEIGHT_MEDIUM 400
+#define FONT_WEIGHT_BOLD   700
+#define FONT_SLANT_NONE    0
+#define FONT_SLANT_ITALIC  100
+#define FONT_SLANT_OBLIQUE 110
+
+
 /* Opaque objects internally used by libass.  Contents are private. */
 typedef struct ass_renderer ASS_Renderer;
 typedef struct render_priv ASS_RenderPriv;
 typedef struct parser_priv ASS_ParserPriv;
 typedef struct ass_library ASS_Library;
+typedef struct font_provider ASS_FontProvider;
+
+
+/* Font Provider */
+typedef void *(*GetFaceFunc)(void *, size_t *);
+typedef int  (*CheckGlyphFunc)(void *, uint32_t);
+typedef void (*DestroyFontFunc)(void *);
+typedef void (*DestroyProviderFunc)(void *);
+
+typedef struct font_provider_funcs {
+    GetFaceFunc     get_face;       // callback for memory fonts
+    CheckGlyphFunc  check_glyph;    // test codepoint for coverage
+    DestroyFontFunc destroy_font;   // destroy a single font
+    DestroyProviderFunc destroy_provider;   // destroy provider only
+} ASS_FontProviderFuncs;
+
+/*
+ * Basic font metadata. All strings must be encoded with UTF-8.
+ * At minimum `family' is required.
+ */
+typedef struct font_provider_meta_data {
+    char *family;       // English font family, e.g. "Arial"
+    char **fullnames;   // list of localized full names, e.g. "Arial Bold"
+    int n_fullname;     // number of localized full names
+    int slant;          // uses the above scale (NONE/ITALIC/OBLIQUE)
+    int weight;         // TrueType scale, 100-900
+} ASS_FontProviderMetaData;
+
 
 /* ASS Style: line */
 typedef struct ass_style {
@@ -63,6 +100,7 @@ typedef struct ass_style {
     double Blur;
 } ASS_Style;
 
+
 /*
  * ASS_Event corresponds to a single Dialogue line;
  * text is stored as-is, style overrides will be parsed later.
index 89e212c25e0930ad6171bc304390e19ed19eb88f..aafb7a8b7927c6961f47e67987e9684d6beeec0a 100644 (file)
@@ -41,3 +41,6 @@ ass_set_line_position
 ass_set_pixel_aspect
 ass_set_selective_style_override_enabled
 ass_set_selective_style_override
+ass_create_font_provider
+ass_font_provider_add_font
+ass_font_provider_free