diff options
-rw-r--r-- | common.h | 19 | ||||
-rw-r--r-- | demo.c | 2 | ||||
-rw-r--r-- | libskrift.h | 7 | ||||
-rw-r--r-- | libskrift_create_context.c | 28 | ||||
-rw-r--r-- | libskrift_free_context.c | 3 |
5 files changed, 40 insertions, 19 deletions
@@ -14,15 +14,6 @@ #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define MAX(A, B) ((A) > (B) ? (A) : (B)) -struct libskrift_context { - LIBSKRIFT_FONT *font; - struct libskrift_rendering rendering; - struct SFT schrift_ctx; - char subpixel_horizontally; - char subpixel_vertically; - char subpixel_bgr; -}; - struct libskrift_font { SFT_Font *font; void *memory_free; @@ -30,3 +21,13 @@ struct libskrift_font { size_t memory_size; size_t refcount; }; + +struct libskrift_context { + struct libskrift_rendering rendering; + struct SFT schrift_ctx; + char subpixel_horizontally; + char subpixel_vertically; + char subpixel_bgr; + size_t nfonts; + LIBSKRIFT_FONT *fonts[]; +}; @@ -25,7 +25,7 @@ main(void) return -1; } height = libskrift_points_to_pixels(72, &rendering); - if (libskrift_create_context(&ctx, font, &rendering, height)) { + if (libskrift_create_context(&ctx, &font, 1, height, &rendering)) { perror("libskrift_create_context"); return -1; } diff --git a/libskrift.h b/libskrift.h index 0ec54fe..1fa0085 100644 --- a/libskrift.h +++ b/libskrift.h @@ -56,7 +56,10 @@ enum libskrift_hinting { #define LIBSKRIFT_REGRESS_TO_GRID 0x00000400U /* Combine with LIBSKRIFT_ADVANCE_TO_GRID for closest alternative */ #define LIBSKRIFT_USE_SUBPIXEL_GRID 0x00000800U #define LIBSKRIFT_VERTICAL_TEXT 0x00001000U -#define LIBSKRIFT_AUTOHINTING 0x00002000U +#define LIBSKRIFT_AUTOHINTING 0x00002000U /* Use autohinter even if hint information exists */ +#define LIBSKRIFT_NO_AUTOHINTING 0x00004000U /* Use autohinter if no hint information exist */ +#define LIBSKRIFT_AUTOKERNING 0x00008000U /* Use autokerner even if kerning information exists */ +#define LIBSKRIFT_NO_AUTOKERNING 0x00010000U /* Use autokerner if no kerning information exist */ struct libskrift_rendering { int struct_version; @@ -164,7 +167,7 @@ void libskrift_close_font(LIBSKRIFT_FONT *); _LIBSKRIFT_GCC_ONLY(__attribute__((__nonnull__(1, 2)))) -int libskrift_create_context(LIBSKRIFT_CONTEXT **, LIBSKRIFT_FONT *, const struct libskrift_rendering *, double); +int libskrift_create_context(LIBSKRIFT_CONTEXT **, LIBSKRIFT_FONT **, size_t, double, const struct libskrift_rendering *); void libskrift_free_context(LIBSKRIFT_CONTEXT *); diff --git a/libskrift_create_context.c b/libskrift_create_context.c index 9ebec24..4adf179 100644 --- a/libskrift_create_context.c +++ b/libskrift_create_context.c @@ -1,8 +1,13 @@ /* See LICENSE file for copyright and license details. */ #include "common.h" +#define FORCED_FLAGS (LIBSKRIFT_NO_LIGATURES |\ + LIBSKRIFT_NO_AUTOHINTING |\ + LIBSKRIFT_NO_AUTOKERNING) + #define IMPLEMENTED_FLAGS (LIBSKRIFT_CORRECT_GAMMA |\ - LIBSKRIFT_REMOVE_GAMMA) /* libschrift does not add gamma, so not handling is required */ + LIBSKRIFT_REMOVE_GAMMA |\ + FORCED_FLAGS) /* libschrift does not add gamma, so not handling is required */ #define HAVE_MULTIPLE_FLAGS(HAVE, CHECK) (((HAVE) & (CHECK)) & (((HAVE) & (CHECK)) - 1)) @@ -12,8 +17,16 @@ static const struct libskrift_rendering default_rendering = LIBSKRIFT_DEFAULT_RENDERING; int -libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT *font, const struct libskrift_rendering *rendering, double height) +libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT **fonts, size_t nfonts, double height, + const struct libskrift_rendering *rendering) { + size_t i; + + if (!nfonts) { + errno = EINVAL; + return -1; + } + if (rendering) { if (HAVE_MULTIPLE_FLAGS(rendering->flags, LIBSKRIFT_CORRECT_GAMMA | LIBSKRIFT_REMOVE_GAMMA) || !rendering->grid_fineness) { @@ -22,13 +35,16 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT *font, const s } } - *ctxp = calloc(1, sizeof(**ctxp)); + *ctxp = calloc(1, offsetof(LIBSKRIFT_CONTEXT, fonts) + nfonts * sizeof(*(*ctxp)->fonts)); if (!*ctxp) return -1; - (*ctxp)->font = font; - (*ctxp)->schrift_ctx.font = font->font; + (*ctxp)->schrift_ctx.font = fonts[0]->font; (*ctxp)->schrift_ctx.yScale = height; + for (i = 0; i < nfonts; i++) { + (*ctxp)->fonts[i] = fonts[i]; + fonts[i]->refcount += 1; + } if (rendering) { memcpy(&(*ctxp)->rendering, rendering, sizeof(*rendering)); @@ -47,6 +63,7 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT *font, const s (*ctxp)->rendering.struct_version = LIBSKRIFT_RENDERING_STRUCT_VERSION; (*ctxp)->rendering.hinting = LIBSKRIFT_NONE; (*ctxp)->rendering.flags &= IMPLEMENTED_FLAGS; + (*ctxp)->rendering.flags |= FORCED_FLAGS; (*ctxp)->rendering.grid_fineness = 1; (*ctxp)->rendering.kerning = 0; (*ctxp)->rendering.interletter_spacing = 0; @@ -78,6 +95,5 @@ libskrift_create_context(LIBSKRIFT_CONTEXT **ctxp, LIBSKRIFT_FONT *font, const s } } - font->refcount += 1; return 0; } diff --git a/libskrift_free_context.c b/libskrift_free_context.c index 2375c05..68ac14d 100644 --- a/libskrift_free_context.c +++ b/libskrift_free_context.c @@ -5,7 +5,8 @@ void libskrift_free_context(LIBSKRIFT_CONTEXT *ctx) { if (ctx) { - libskrift_close_font(ctx->font); + while (ctx->nfonts--) + libskrift_close_font(ctx->fonts[ctx->nfonts]); free(ctx); } } |