summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/css/INDEX1
-rw-r--r--test/data/css/fontface.css142
-rw-r--r--test/dump.h164
3 files changed, 303 insertions, 4 deletions
diff --git a/test/data/css/INDEX b/test/data/css/INDEX
index e918e16..42c66a8 100644
--- a/test/data/css/INDEX
+++ b/test/data/css/INDEX
@@ -7,3 +7,4 @@ allzengarden.css All CSS Zen Garden stylesheets concatenated
blocks.css Basic blocks and at-rule syntax
malformed.css Malformed declarations from the CSS 2.1 spec
badcomment.css Comment inside { ... } lacks starting /*
+fontface.css Various @font-face rules \ No newline at end of file
diff --git a/test/data/css/fontface.css b/test/data/css/fontface.css
new file mode 100644
index 0000000..bf58457
--- /dev/null
+++ b/test/data/css/fontface.css
@@ -0,0 +1,142 @@
+@font-face {
+ invalid-descriptor: name;
+ src: invalid-src;
+}
+
+/* To use a downloadable font called Gentium */
+@font-face {
+ font-family: Gentium;
+ src: url(http://example.com/fonts/Gentium.ttf);
+}
+
+p { font-family: Gentium, serif; }
+
+/* load WOFF font if possible, otherwise use OpenType font */
+@font-face {
+ font-family: bodytext;
+ src: url(ideal-sans-serif.woff) format("woff"),
+ url(basic-sans-serif.ttf) format("opentype");
+}
+
+/* regular face of Gentium */
+@font-face {
+ font-family: MyGentium;
+ src: local(Gentium), /* use locally available Gentium */
+ url(Gentium.ttf); /* otherwise, download it */
+}
+
+/* bold face of Gentium */
+@font-face {
+ font-family: MyGentium;
+ src: local(Gentium Bold), /* full font name */
+ local(Gentium-Bold), /* Postscript name */
+ url(GentiumBold.ttf); /* otherwise, download it */
+ font-weight: bold;
+}
+
+/* Use a local font or reference an SVG font in another document: */
+@font-face {
+ font-family: Headline;
+ src: local(Futura-Medium),
+ url(fonts.svg#MyGeometricModern) format("svg");
+}
+
+/* Create an alias for local Japanese fonts on different platforms: */
+@font-face {
+ font-family: jpgothic;
+ src: local(HiraKakuPro-W3), local(Meiryo), local(IPAPGothic);
+}
+
+/* Reference a font face that cannot be matched within a larger family: */
+@font-face {
+ font-family: Hoefler Text Ornaments;
+ /* has the same font properties as Hoefler Text Regular */
+ src: local(HoeflerText-Ornaments);
+}
+
+/* Since localized fullnames should never match, a document with the header style rules below would always render using the default serif font, regardless whether a particular system locale parameter is set to Finnish or not: */
+@font-face {
+ font-family: SectionHeader;
+ src: local("Arial Lihavoitu"); /* Finnish fullname for Arial Bold, matching should fail */
+ font-weight: bold;
+}
+
+h2 { font-family: SectionHeader, serif; }
+
+/* A conformant user agent should never load the font ‘gentium.eot’ in the example below, since it is included in the first definition of the ‘src’ descriptor which is overridden by the second definition in the same @font-face rule: */
+@font-face {
+ font-family: MainText;
+ src: url(gentium.eot); /* for compatibility with older non-conformant user agents */
+ src: local("Gentium"), url(gentium.ttf); /* Overrides src definition */
+}
+
+/* The BBC provides news services in a wide variety of languages, many that are not well supported across all platforms. Using an @font-face rule, the BBC could provide a font for any of these languages, as it already does via a manual font download. */
+@font-face {
+ font-family: BBCBengali;
+ src: url(fonts/BBCBengali.ttf) format("opentype");
+ unicode-range: U+00-FF, U+980-9FF;
+}
+
+/* Technical documents often require a wide range of symbols. The STIX Fonts project is one project aimed at providing fonts to support a wide range of technical typesetting in a standardized way. The example below shows the use of a font that provides glyphs for many of the mathematical and technical symbol ranges within Unicode: */
+@font-face {
+ font-family: STIXGeneral;
+ src: local(STIXGeneral), url(/stixfonts/STIXGeneral.otf);
+ unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
+}
+
+
+
+@font-face {
+ font-family: JapaneseWithGentium;
+ src: local(MSMincho);
+ /* no range specified, defaults to entire range */
+}
+
+@font-face {
+ font-family: JapaneseWithGentium;
+ src: url(../fonts/Gentium.ttf);
+ unicode-range: U+0-2FF;
+}
+
+/* Consider a family constructed to optimize bandwidth by separating out Latin, Japanese and other characters into different font files: */
+/* fallback font - size: 4.5MB */
+@font-face {
+ font-family: DroidSans;
+ src: url(DroidSansFallback.ttf);
+ /* no range specified, defaults to entire range */
+}
+
+/* Japanese glyphs - size: 1.2MB */
+@font-face {
+ font-family: DroidSans;
+ src: url(DroidSansJapanese.ttf);
+ unicode-range: U+3000-9FFF, U+ff??;
+}
+
+/* Latin, Greek, Cyrillic along with some
+ punctuation and symbols - size: 190KB */
+@font-face {
+ font-family: DroidSans;
+ src: url(DroidSans.ttf);
+ unicode-range: U+000-5FF, U+1e00-1fff, U+2000-2300;
+}
+
+/* The first src: should be used because the second is invalid. */
+@font-face {
+ font-family: BadSrc;
+ src: url(http://example.com/fonts/Gentium.ttf);
+ src: fhgwgads;
+ font-style: oblique;
+}
+
+/* The third src: should be used because the second is invalid, but the thirsd is valid, overriding the first. */
+@font-face {
+ font-family: ThirdSrc;
+ src: url(http://example.com/fonts/Gentium.ttf);
+ src: fhgwgads;
+ font-style: italic;
+ src: local(gentium);
+}
+
+
+
diff --git a/test/dump.h b/test/dump.h
index 7a6d343..8817edf 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -8,6 +8,7 @@
#include "stylesheet.h"
#include "bytecode/bytecode.h"
#include "bytecode/opcodes.h"
+#include "select/font_face.h"
#include "testutils.h"
@@ -18,11 +19,14 @@ static void dump_rule_charset(css_rule_charset *s, char **buf, size_t *buflen);
static void dump_rule_import(css_rule_import *s, char **buf, size_t *buflen);
static void dump_rule_media(css_rule_media *s, char **buf, size_t *buflen);
static void dump_rule_page(css_rule_page *s, char **buf, size_t *buflen);
+static void dump_rule_font_face(css_rule_font_face *s,
+ char **buf, size_t *buflen);
static void dump_selector_list(css_selector *list, char **ptr);
static void dump_selector(css_selector *selector, char **ptr);
static void dump_selector_detail(css_selector_detail *detail, char **ptr);
static void dump_bytecode(css_style *style, char **ptr, uint32_t depth);
static void dump_string(lwc_string *string, char **ptr);
+static void dump_font_face(css_font_face *font_face, char**ptr);
void dump_sheet(css_stylesheet *sheet, char *buf, size_t *buflen)
{
@@ -50,6 +54,10 @@ void dump_sheet(css_stylesheet *sheet, char *buf, size_t *buflen)
dump_rule_page((css_rule_page *) rule,
&buf, buflen);
break;
+ case CSS_RULE_FONT_FACE:
+ dump_rule_font_face((css_rule_font_face *) rule,
+ &buf, buflen);
+ break;
default:
{
int written = sprintf(buf, "Unhandled rule type %d\n",
@@ -157,6 +165,22 @@ void dump_rule_page(css_rule_page *s, char **buf, size_t *buflen)
*buf = ptr;
}
+void dump_rule_font_face(css_rule_font_face *s, char **buf, size_t *buflen)
+{
+ char *ptr = *buf;
+
+ ptr += sprintf(ptr, "| @font-face ");
+
+ if (s->font_face != NULL) {
+ dump_font_face(s->font_face, &ptr);
+ }
+
+ *ptr++ = '\n';
+
+ *buflen -= ptr - *buf;
+ *buf = ptr;
+}
+
void dump_selector_list(css_selector *list, char **ptr)
{
if (list->combinator != NULL) {
@@ -833,7 +857,8 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
break;
case BACKGROUND_IMAGE_URI:
{
- uint32_t snum = *((uint32_t *) bytecode); lwc_string *he;
+ uint32_t snum = *((uint32_t *) bytecode);
+ lwc_string *he;
css__stylesheet_string_get(style->sheet,
snum,
&he);
@@ -2017,9 +2042,7 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
(int) lwc_string_length(he),
lwc_string_data(he));
- he =
- *((lwc_string **)
- bytecode);
+ css__stylesheet_string_get(style->sheet, snum, &he);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, " '%.*s' ",
(int) lwc_string_length(he),
@@ -2365,4 +2388,137 @@ void dump_string(lwc_string *string, char **ptr)
lwc_string_data(string));
}
+void dump_font_face(css_font_face *font_face, char **ptr)
+{
+ uint8_t style, weight;
+
+ if (font_face->font_family != NULL) {
+ *(*ptr)++ = '\n';
+ *ptr += sprintf(*ptr, "| font-family: %.*s",
+ (int) lwc_string_length(font_face->font_family),
+ lwc_string_data(font_face->font_family));
+ }
+
+ *ptr += sprintf(*ptr, "\n| font-style: ");
+ style = css_font_face_font_style(font_face);
+ switch (style) {
+ case CSS_FONT_STYLE_INHERIT:
+ *ptr += sprintf(*ptr, "unspecified");
+ break;
+ case CSS_FONT_STYLE_NORMAL:
+ *ptr += sprintf(*ptr, "normal");
+ break;
+ case CSS_FONT_STYLE_ITALIC:
+ *ptr += sprintf(*ptr, "italic");
+ break;
+ case CSS_FONT_STYLE_OBLIQUE:
+ *ptr += sprintf(*ptr, "oblique");
+ break;
+ }
+
+ *ptr += sprintf(*ptr, "\n| font-weight: ");
+ weight = css_font_face_font_weight(font_face);
+ switch (weight) {
+ case CSS_FONT_WEIGHT_INHERIT:
+ *ptr += sprintf(*ptr, "unspecified");
+ break;
+ case CSS_FONT_WEIGHT_NORMAL:
+ *ptr += sprintf(*ptr, "normal");
+ break;
+ case CSS_FONT_WEIGHT_BOLD:
+ *ptr += sprintf(*ptr, "bold");
+ break;
+ case CSS_FONT_WEIGHT_100:
+ *ptr += sprintf(*ptr, "100");
+ break;
+ case CSS_FONT_WEIGHT_200:
+ *ptr += sprintf(*ptr, "200");
+ break;
+ case CSS_FONT_WEIGHT_300:
+ *ptr += sprintf(*ptr, "300");
+ break;
+ case CSS_FONT_WEIGHT_400:
+ *ptr += sprintf(*ptr, "400");
+ break;
+ case CSS_FONT_WEIGHT_500:
+ *ptr += sprintf(*ptr, "500");
+ break;
+ case CSS_FONT_WEIGHT_600:
+ *ptr += sprintf(*ptr, "600");
+ break;
+ case CSS_FONT_WEIGHT_700:
+ *ptr += sprintf(*ptr, "700");
+ break;
+ case CSS_FONT_WEIGHT_800:
+ *ptr += sprintf(*ptr, "800");
+ break;
+ case CSS_FONT_WEIGHT_900:
+ *ptr += sprintf(*ptr, "900");
+ break;
+ default:
+ *ptr += sprintf(*ptr, "Unhandled weight %d\n", (int)weight);
+ break;
+ }
+
+
+ if (font_face->srcs != NULL) {
+ uint32_t i;
+ css_font_face_src *srcs = font_face->srcs;
+ for (i = 0; i < font_face->n_srcs; ++i) {
+ *ptr += sprintf(*ptr, "\n| src: ");
+
+ css_font_face_format format =
+ css_font_face_src_format(&srcs[i]);
+
+ *ptr += sprintf(*ptr, "\n| format: ");
+
+ switch (format) {
+ case CSS_FONT_FACE_FORMAT_UNSPECIFIED:
+ *ptr += sprintf(*ptr, "unspecified");
+ break;
+ case CSS_FONT_FACE_FORMAT_WOFF:
+ *ptr += sprintf(*ptr, "WOFF");
+ break;
+ case CSS_FONT_FACE_FORMAT_OPENTYPE:
+ *ptr += sprintf(*ptr, "OTF");
+ break;
+ case CSS_FONT_FACE_FORMAT_EMBEDDED_OPENTYPE:
+ *ptr += sprintf(*ptr, "EOTF");
+ break;
+ case CSS_FONT_FACE_FORMAT_SVG:
+ *ptr += sprintf(*ptr, "SVG");
+ break;
+ case CSS_FONT_FACE_FORMAT_UNKNOWN:
+ *ptr += sprintf(*ptr, "unknown");
+ break;
+ default:
+ *ptr += sprintf(*ptr, "UNEXPECTED");
+ break;
+ }
+
+ if (srcs[i].location != NULL) {
+ *ptr += sprintf(*ptr, "\n| location: ");
+
+ switch (css_font_face_src_location_type(
+ &srcs[i])) {
+ case CSS_FONT_FACE_LOCATION_TYPE_LOCAL:
+ *ptr += sprintf(*ptr, "local");
+ break;
+ case CSS_FONT_FACE_LOCATION_TYPE_URI:
+ *ptr += sprintf(*ptr, "url");
+ break;
+ default:
+ *ptr += sprintf(*ptr, "UNKNOWN");
+ break;
+ }
+
+ *ptr += sprintf(*ptr, "(%.*s)",
+ (int) lwc_string_length(
+ srcs[i].location),
+ lwc_string_data(srcs[i].location));
+ }
+ }
+ }
+}
+
#endif