From d5a183e14d42560632a6aa270aede226215bb3d3 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 4 Dec 2011 21:06:24 +0000 Subject: @font-face support. Credit: James Montgomerie Things missing: parser tests; the following descriptors: font-feature-settings, font-stretch, font-variant, unicode-range. svn path=/trunk/libcss/; revision=13244 --- include/libcss/font_face.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++ include/libcss/libcss.h | 1 + include/libcss/select.h | 21 +++++++++++- include/libcss/types.h | 4 +++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 include/libcss/font_face.h (limited to 'include') diff --git a/include/libcss/font_face.h b/include/libcss/font_face.h new file mode 100644 index 0000000..6b18433 --- /dev/null +++ b/include/libcss/font_face.h @@ -0,0 +1,79 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2011 Things Made Out Of Other Things Ltd. + * Written by James Montgomerie + */ + +#ifndef libcss_font_face_h_ +#define libcss_font_face_h_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +#include +#include +#include +#include + +typedef enum css_font_face_format { + CSS_FONT_FACE_FORMAT_UNSPECIFIED = 0x00, + + CSS_FONT_FACE_FORMAT_WOFF = 0x01, + /* WOFF (Web Open Font Format); .woff */ + CSS_FONT_FACE_FORMAT_OPENTYPE = 0x02, + /* TrueType or OpenType; .ttf, .otf */ + CSS_FONT_FACE_FORMAT_EMBEDDED_OPENTYPE = 0x04, + /* Embedded OpenType; .eot */ + CSS_FONT_FACE_FORMAT_SVG = 0x08, + /* SVG Font; .svg, .svgz */ + + CSS_FONT_FACE_FORMAT_UNKNOWN = 0x10, + /* Format specified, but not recognised */ + + /* We don't define CSS_FONT_FACE_SRC_FORMAT_TRUETYPE as might be + * expected, because the CSS3 specification + * (http://www.w3.org/TR/css3-fonts/, ยง4.3) says: + * "Given the overlap in common usage between TrueType and + * OpenType, the format hints "truetype" and "opentype" must be + * considered as synonymous" + * so we compute a hint of 'truetype' to css_font_face_format_opentype. + */ +} css_font_face_format; + +typedef enum css_font_face_location_type { + CSS_FONT_FACE_LOCATION_TYPE_UNSPECIFIED = 0, + CSS_FONT_FACE_LOCATION_TYPE_LOCAL = 1, + CSS_FONT_FACE_LOCATION_TYPE_URI = 2, +} css_font_face_location_type; + + +css_error css_font_face_get_font_family( + const css_font_face *font_face, + lwc_string **font_family); + +css_error css_font_face_count_srcs(const css_font_face *font_face, + uint32_t *count); +css_error css_font_face_get_src(const css_font_face *font_face, uint32_t index, + const css_font_face_src **src); + +css_error css_font_face_src_get_location(const css_font_face_src *src, + lwc_string **location); + +css_font_face_location_type css_font_face_src_location_type( + const css_font_face_src *src); +css_font_face_format css_font_face_src_format(const css_font_face_src *src); + +uint8_t css_font_face_font_style(const css_font_face *font_face); +uint8_t css_font_face_font_weight(const css_font_face *font_face); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libcss/libcss.h b/include/libcss/libcss.h index 551177c..89e83b5 100644 --- a/include/libcss/libcss.h +++ b/include/libcss/libcss.h @@ -22,6 +22,7 @@ extern "C" #include #include #include +#include #ifdef __cplusplus } diff --git a/include/libcss/select.h b/include/libcss/select.h index b6f9475..4a95752 100644 --- a/include/libcss/select.h +++ b/include/libcss/select.h @@ -130,6 +130,20 @@ typedef struct css_select_handler { css_hint *size); } css_select_handler; +/** + * Font face selection result set + */ +typedef struct css_select_font_faces_results { + css_allocator_fn alloc; + void *pw; + + /** + * Array of pointers to computed font faces. + */ + css_font_face **font_faces; + uint32_t n_font_faces; +} css_select_font_faces_results; + css_error css_select_ctx_create(css_allocator_fn alloc, void *pw, css_select_ctx **result); css_error css_select_ctx_destroy(css_select_ctx *ctx); @@ -151,8 +165,13 @@ css_error css_select_style(css_select_ctx *ctx, void *node, uint64_t media, const css_stylesheet *inline_style, css_select_handler *handler, void *pw, css_select_results **result); +css_error css_select_results_destroy(css_select_results *results); -css_error css_select_results_destroy(css_select_results *results); +css_error css_select_font_faces(css_select_ctx *ctx, + uint64_t media, lwc_string *font_family, + css_select_font_faces_results **result); +css_error css_select_font_faces_results_destroy( + css_select_font_faces_results *results); #ifdef __cplusplus } diff --git a/include/libcss/types.h b/include/libcss/types.h index c8b9cf9..ffaf13c 100644 --- a/include/libcss/types.h +++ b/include/libcss/types.h @@ -127,6 +127,10 @@ typedef struct css_select_ctx css_select_ctx; typedef struct css_computed_style css_computed_style; +typedef struct css_font_face css_font_face; + +typedef struct css_font_face_src css_font_face_src; + #ifdef __cplusplus } #endif -- cgit v1.2.3