neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

wld.patch (19591B)


      1 Subject: clips, fonts, the target for the CPU, fonts opened by file and fontconfig optional
      2 
      3 diff --git a/font.c b/font.c
      4 index cbb187c..7c6b52f 100644
      5 --- a/font.c
      6 +++ b/font.c
      7 @@ -23,7 +23,10 @@
      8  
      9  #include "wld-private.h"
     10  
     11 +#ifdef WLD_FONTCONFIG
     12  #include <fontconfig/fcfreetype.h>
     13 +#endif
     14 +#include <string.h>
     15  
     16  EXPORT
     17  struct wld_font_context *
     18 @@ -58,6 +61,62 @@ wld_font_destroy_context(struct wld_font_context *context)
     19  	free(context);
     20  }
     21  
     22 +/* A FreeType face put at a size: the font every way of opening one ends in. */
     23 +static struct wld_font *
     24 +open_face(struct wld_font_context *context, FT_Face face, double pixel_size,
     25 +          double aspect)
     26 +{
     27 +	struct font *font;
     28 +
     29 +	font = malloc(sizeof *font);
     30 +
     31 +	if (!font) {
     32 +		FT_Done_Face(face);
     33 +		return NULL;
     34 +	}
     35 +
     36 +	font->context = context;
     37 +	font->face = face;
     38 +	memset(font->chars, 0, sizeof font->chars);
     39 +
     40 +	if (font->face->face_flags & FT_FACE_FLAG_SCALABLE) {
     41 +		FT_F26Dot6 width, height;
     42 +
     43 +		width = ((unsigned int)pixel_size) << 6;
     44 +		height = ((unsigned int)(pixel_size * aspect)) << 6;
     45 +
     46 +		FT_Set_Char_Size(font->face, width, height, 0, 0);
     47 +	} else {
     48 +		FT_Set_Pixel_Sizes(font->face, (unsigned int)pixel_size,
     49 +		                   (unsigned int)(pixel_size * aspect));
     50 +	}
     51 +
     52 +	font->base.ascent = font->face->size->metrics.ascender >> 6;
     53 +	font->base.descent = -font->face->size->metrics.descender >> 6;
     54 +	font->base.height = font->base.ascent + font->base.descent;
     55 +	font->base.max_advance = font->face->size->metrics.max_advance >> 6;
     56 +
     57 +	font->glyphs = calloc(font->face->num_glyphs, sizeof(struct glyph *));
     58 +
     59 +	return &font->base;
     60 +}
     61 +
     62 +EXPORT
     63 +struct wld_font *
     64 +wld_font_open_file(struct wld_font_context *context, const char *path,
     65 +                   int index, double pixel_size)
     66 +{
     67 +	FT_Face face;
     68 +
     69 +	DEBUG("Loading font file: %s\n", path);
     70 +
     71 +	if (FT_New_Face(context->library, path, index, &face) != 0)
     72 +		return NULL;
     73 +
     74 +	return open_face(context, face, pixel_size, 1.0);
     75 +}
     76 +
     77 +#ifdef WLD_FONTCONFIG
     78  EXPORT
     79  struct wld_font *
     80  wld_font_open_name(struct wld_font_context *context, const char *name)
     81 @@ -84,71 +143,35 @@ struct wld_font *
     82  wld_font_open_pattern(struct wld_font_context *context, FcPattern *match)
     83  {
     84  	char *filename;
     85 -	struct font *font;
     86 +	FT_Face face;
     87  	FcResult result;
     88 -	double pixel_size, aspect;
     89 -
     90 -	font = malloc(sizeof *font);
     91 -
     92 -	if (!font)
     93 -		goto error0;
     94 -
     95 -	font->context = context;
     96 +	double pixel_size = 12, aspect;
     97 +	int index = 0;
     98  
     99  	result = FcPatternGetString(match, FC_FILE, 0, (FcChar8 **)&filename);
    100 +	FcPatternGetInteger(match, FC_INDEX, 0, &index);
    101  
    102  	if (result == FcResultMatch) {
    103 -		FT_Error error;
    104 -
    105  		DEBUG("Loading font file: %s\n", filename);
    106  
    107 -		error = FT_New_Face(context->library, filename, 0, &font->face);
    108 -
    109 -		if (error == 0)
    110 +		if (FT_New_Face(context->library, filename, index, &face) == 0)
    111  			goto load_face;
    112  	}
    113  
    114 -	result = FcPatternGetFTFace(match, FC_FT_FACE, 0, &font->face);
    115 -
    116 -	if (result != FcResultMatch) {
    117 +	if (FcPatternGetFTFace(match, FC_FT_FACE, 0, &face) != FcResultMatch) {
    118  		DEBUG("Couldn't determine font filename or FreeType face\n");
    119 -		goto error1;
    120 +		return NULL;
    121  	}
    122  
    123  load_face:
    124 -	result = FcPatternGetDouble(match, FC_PIXEL_SIZE, 0, &pixel_size);
    125 +	FcPatternGetDouble(match, FC_PIXEL_SIZE, 0, &pixel_size);
    126  
    127 -	result = FcPatternGetDouble(match, FC_ASPECT, 0, &aspect);
    128 -
    129 -	if (result == FcResultNoMatch)
    130 +	if (FcPatternGetDouble(match, FC_ASPECT, 0, &aspect) != FcResultMatch)
    131  		aspect = 1.0;
    132  
    133 -	if (font->face->face_flags & FT_FACE_FLAG_SCALABLE) {
    134 -		FT_F26Dot6 width, height;
    135 -
    136 -		width = ((unsigned int)pixel_size) << 6;
    137 -		height = ((unsigned int)(pixel_size * aspect)) << 6;
    138 -
    139 -		FT_Set_Char_Size(font->face, width, height, 0, 0);
    140 -	} else {
    141 -		FT_Set_Pixel_Sizes(font->face, (unsigned int)pixel_size,
    142 -		                   (unsigned int)(pixel_size * aspect));
    143 -	}
    144 -
    145 -	font->base.ascent = font->face->size->metrics.ascender >> 6;
    146 -	font->base.descent = -font->face->size->metrics.descender >> 6;
    147 -	font->base.height = font->base.ascent + font->base.descent;
    148 -	font->base.max_advance = font->face->size->metrics.max_advance >> 6;
    149 -
    150 -	font->glyphs = calloc(font->face->num_glyphs, sizeof(struct glyph *));
    151 -
    152 -	return &font->base;
    153 -
    154 -error1:
    155 -	free(font);
    156 -error0:
    157 -	return NULL;
    158 +	return open_face(context, face, pixel_size, aspect);
    159  }
    160 +#endif
    161  
    162  EXPORT
    163  void
    164 @@ -160,6 +183,20 @@ wld_font_close(struct wld_font *font_base)
    165  	free(font);
    166  }
    167  
    168 +FT_UInt
    169 +font_char_index(struct font *font, uint32_t character)
    170 +{
    171 +	unsigned slot = character % FONT_CHAR_CACHE;
    172 +
    173 +	/* the key is the character plus one, so an empty slot (0) matches
    174 +	 * nothing and a character the face lacks is remembered too */
    175 +	if (font->chars[slot].key != character + 1) {
    176 +		font->chars[slot].key = character + 1;
    177 +		font->chars[slot].index = FT_Get_Char_Index(font->face, character);
    178 +	}
    179 +	return font->chars[slot].index;
    180 +}
    181 +
    182  bool
    183  font_ensure_glyph(struct font *font, FT_UInt glyph_index)
    184  {
    185 @@ -200,11 +237,31 @@ wld_font_ensure_char(struct wld_font *font_base, uint32_t character)
    186  	struct font *font = (void *)font_base;
    187  	FT_UInt glyph_index;
    188  
    189 -	glyph_index = FT_Get_Char_Index(font->face, character);
    190 +	glyph_index = font_char_index(font, character);
    191  
    192  	return font_ensure_glyph(font, glyph_index);
    193  }
    194  
    195 +EXPORT
    196 +uint32_t
    197 +wld_font_char_by_name(struct wld_font *font_base, const char *name)
    198 +{
    199 +	struct font *font = (void *)font_base;
    200 +	FT_UInt glyph_index, index;
    201 +	FT_ULong c;
    202 +
    203 +	if (!FT_HAS_GLYPH_NAMES(font->face))
    204 +		return 0;
    205 +	glyph_index = FT_Get_Name_Index(font->face, (FT_String *)name);
    206 +	if (!glyph_index)
    207 +		return 0;
    208 +	for (c = FT_Get_First_Char(font->face, &index); index; c = FT_Get_Next_Char(font->face, c, &index)) {
    209 +		if (index == glyph_index)
    210 +			return c;
    211 +	}
    212 +	return 0;
    213 +}
    214 +
    215  EXPORT
    216  void
    217  wld_font_text_extents_n(struct wld_font *font_base,
    218 @@ -216,16 +273,42 @@ wld_font_text_extents_n(struct wld_font *font_base,
    219  	uint32_t c;
    220  	FT_UInt glyph_index;
    221  
    222 +	struct glyph *glyph;
    223 +	int32_t x1 = INT32_MAX, y1 = INT32_MAX, x2 = INT32_MIN, y2 = INT32_MIN;
    224 +
    225  	extents->advance = 0;
    226  
    227 -	while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') {
    228 +	while ((ret = wld_utf8_decode(text, length, &c)) > 0 && c != '\0') {
    229  		length -= ret;
    230  		text += ret;
    231 -		glyph_index = FT_Get_Char_Index(font->face, c);
    232 +		glyph_index = font_char_index(font, c);
    233  
    234  		if (!font_ensure_glyph(font, glyph_index))
    235  			continue;
    236  
    237 -		extents->advance += font->glyphs[glyph_index]->advance;
    238 +		glyph = font->glyphs[glyph_index];
    239 +		if (glyph->bitmap.width && glyph->bitmap.rows) {
    240 +			int32_t gx = (int32_t)extents->advance + glyph->x;
    241 +
    242 +			if (gx < x1)
    243 +				x1 = gx;
    244 +			if (glyph->y < y1)
    245 +				y1 = glyph->y;
    246 +			if (gx + (int32_t)glyph->bitmap.width > x2)
    247 +				x2 = gx + glyph->bitmap.width;
    248 +			if (glyph->y + (int32_t)glyph->bitmap.rows > y2)
    249 +				y2 = glyph->y + glyph->bitmap.rows;
    250 +		}
    251 +		extents->advance += glyph->advance;
    252 +	}
    253 +
    254 +	if (x1 > x2) {
    255 +		extents->ink_x = extents->ink_y = 0;
    256 +		extents->ink_width = extents->ink_height = 0;
    257 +		return;
    258  	}
    259 +	extents->ink_x = x1;
    260 +	extents->ink_y = y1;
    261 +	extents->ink_width = x2 - x1;
    262 +	extents->ink_height = y2 - y1;
    263  }
    264 diff --git a/intel.c b/intel.c
    265 index 8cf0a21..b684270 100644
    266 --- a/intel.c
    267 +++ b/intel.c
    268 @@ -313,10 +313,10 @@ renderer_draw_text(struct wld_renderer *base,
    269  	if (length == -1)
    270  		length = strlen(text);
    271  
    272 -	while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') {
    273 +	while ((ret = wld_utf8_decode(text, length, &c)) > 0 && c != '\0') {
    274  		text += ret;
    275  		length -= ret;
    276 -		glyph_index = FT_Get_Char_Index(font->face, c);
    277 +		glyph_index = font_char_index(font, c);
    278  
    279  		if (!font_ensure_glyph(font, glyph_index))
    280  			continue;
    281 diff --git a/interface/renderer.h b/interface/renderer.h
    282 index ed34b3d..1c5e693 100644
    283 --- a/interface/renderer.h
    284 +++ b/interface/renderer.h
    285 @@ -47,6 +47,10 @@ static void renderer_draw_text(struct wld_renderer *renderer,
    286                                 int32_t x, int32_t y,
    287                                 const char *text, uint32_t length,
    288                                 struct wld_extents *extents);
    289 +#ifdef RENDERER_IMPLEMENTS_CLIP
    290 +static void renderer_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y,
    291 +                              uint32_t width, uint32_t height);
    292 +#endif
    293  static void renderer_flush(struct wld_renderer *renderer);
    294  static void renderer_destroy(struct wld_renderer *renderer);
    295  
    296 @@ -65,6 +69,9 @@ static const struct wld_renderer_impl wld_renderer_impl = {
    297  	.draw_circle = &wld_draw_circle,
    298  	.draw_line = &wld_draw_line,
    299  	.draw_text = &renderer_draw_text,
    300 +#ifdef RENDERER_IMPLEMENTS_CLIP
    301 +	.set_clip = &renderer_set_clip,
    302 +#endif
    303  	.flush = &renderer_flush,
    304  	.destroy = &renderer_destroy
    305  };
    306 diff --git a/meson.build b/meson.build
    307 index 4de1248..ca762e9 100644
    308 --- a/meson.build
    309 +++ b/meson.build
    310 @@ -40,9 +40,17 @@ c_args = cc.get_supported_arguments([
    311  ]
    312  
    313  requires = [
    314 -  dependency('fontconfig'),
    315    dependency('pixman-1'),
    316  ]
    317 +# fontconfig, where it is, finds fonts by name; without it a font is opened
    318 +# from its file (wld_font_open_file), as a system without fontconfig has to
    319 +fontconfig = dependency('fontconfig', required: get_option('fontconfig'))
    320 +extra_cflags = []
    321 +if fontconfig.found()
    322 +  requires += fontconfig
    323 +  c_args += '-DWLD_FONTCONFIG'
    324 +  extra_cflags += '-DWLD_FONTCONFIG'
    325 +endif
    326  requires_private = [
    327    dependency('freetype2'),
    328  ]
    329 @@ -128,6 +136,7 @@ pkg.generate(
    330    description: 'A primitive drawing library library targeted at Wayland',
    331    requires: requires,
    332    requires_private: requires_private,
    333 +  extra_cflags: extra_cflags,
    334  )
    335  
    336  doxygen = find_program('doxygen', required: get_option('doxygen'))
    337 diff --git a/meson.options b/meson.options
    338 index 0dc80cf..cb19e40 100644
    339 --- a/meson.options
    340 +++ b/meson.options
    341 @@ -1,4 +1,5 @@
    342  option('wayland', type: 'feature', value: 'auto', description: 'Wayland frontend')
    343  option('drm', type: 'feature', value: 'auto', description: 'Enable libdrm backend')
    344  option('drivers', type: 'array', choices: ['auto', 'intel', 'nouveau'], value: ['auto'], description: 'libdrm drivers')
    345 +option('fontconfig', type: 'feature', value: 'auto', description: 'Find fonts by name through fontconfig')
    346  option('doxygen', type: 'feature', value: 'auto', description: 'Build documentation')
    347 diff --git a/nouveau.c b/nouveau.c
    348 index 6bd7ab1..c22bb21 100644
    349 --- a/nouveau.c
    350 +++ b/nouveau.c
    351 @@ -596,10 +596,10 @@ renderer_draw_text(struct wld_renderer *base,
    352  	if (length == -1)
    353  		length = strlen(text);
    354  
    355 -	while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') {
    356 +	while ((ret = wld_utf8_decode(text, length, &c)) > 0 && c != '\0') {
    357  		text += ret;
    358  		length -= ret;
    359 -		glyph_index = FT_Get_Char_Index(font->face, c);
    360 +		glyph_index = font_char_index(font, c);
    361  
    362  		if (!font_ensure_glyph(font, glyph_index))
    363  			continue;
    364 diff --git a/pixman.c b/pixman.c
    365 index ed7788f..0c2ea1f 100644
    366 --- a/pixman.c
    367 +++ b/pixman.c
    368 @@ -37,6 +37,7 @@
    369  struct pixman_renderer {
    370  	struct wld_renderer base;
    371  	pixman_image_t *target;
    372 +	uint32_t target_width, target_height;
    373  	pixman_glyph_cache_t *glyph_cache;
    374  };
    375  
    376 @@ -53,6 +54,7 @@ struct pixman_map {
    377  
    378  #include "interface/context.h"
    379  #define RENDERER_IMPLEMENTS_REGION
    380 +#define RENDERER_IMPLEMENTS_CLIP
    381  #include "interface/buffer.h"
    382  #include "interface/renderer.h"
    383  IMPL(pixman_renderer, wld_renderer)
    384 @@ -258,13 +260,39 @@ renderer_set_target(struct wld_renderer *base, struct buffer *buffer)
    385  	if (renderer->target)
    386  		pixman_image_unref(renderer->target);
    387  
    388 -	if (buffer)
    389 -		return (renderer->target = pixman_image(buffer));
    390 +	if (buffer) {
    391 +		if (!(renderer->target = pixman_image(buffer)))
    392 +			return false;
    393 +
    394 +		/* solid fills only clip against an explicit region */
    395 +		renderer->target_width = buffer->base.width;
    396 +		renderer->target_height = buffer->base.height;
    397 +		renderer_set_clip(base, 0, 0, buffer->base.width, buffer->base.height);
    398 +		return true;
    399 +	}
    400  
    401  	renderer->target = NULL;
    402  	return true;
    403  }
    404  
    405 +void
    406 +renderer_set_clip(struct wld_renderer *base, int32_t x, int32_t y,
    407 +                  uint32_t width, uint32_t height)
    408 +{
    409 +	struct pixman_renderer *renderer = pixman_renderer(base);
    410 +	pixman_region32_t clip, bounds;
    411 +
    412 +	if (!renderer->target)
    413 +		return;
    414 +	pixman_region32_init_rect(&bounds, 0, 0, renderer->target_width,
    415 +	                          renderer->target_height);
    416 +	pixman_region32_init_rect(&clip, x, y, width, height);
    417 +	pixman_region32_intersect(&clip, &clip, &bounds);
    418 +	pixman_image_set_clip_region32(renderer->target, &clip);
    419 +	pixman_region32_fini(&clip);
    420 +	pixman_region32_fini(&bounds);
    421 +}
    422 +
    423  void
    424  renderer_fill_rectangle(struct wld_renderer *base, uint32_t color,
    425                          int32_t x, int32_t y,
    426 @@ -423,10 +451,10 @@ renderer_draw_text(struct wld_renderer *base,
    427  		return;
    428  	solid = pixman_image_create_solid_fill(&pixman_color);
    429  
    430 -	while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') {
    431 +	while ((ret = wld_utf8_decode(text, length, &c)) > 0 && c != '\0') {
    432  		text += ret;
    433  		length -= ret;
    434 -		glyph_index = FT_Get_Char_Index(font->face, c);
    435 +		glyph_index = font_char_index(font, c);
    436  
    437  		if (!font_ensure_glyph(font, glyph_index))
    438  			continue;
    439 diff --git a/renderer.c b/renderer.c
    440 index 2f49bc8..c1c17ff 100644
    441 --- a/renderer.c
    442 +++ b/renderer.c
    443 @@ -195,6 +195,28 @@ unmap_src:
    444  	wld_unmap(buffer);
    445  }
    446  
    447 +EXPORT
    448 +void *
    449 +wld_target_map(struct wld_renderer *renderer, uint32_t *pitch, uint32_t *format)
    450 +{
    451 +	if (!renderer->target)
    452 +		return NULL;
    453 +	/* accelerator writes land before the CPU looks */
    454 +	renderer->impl->flush(renderer);
    455 +	if (!wld_map(renderer->target))
    456 +		return NULL;
    457 +	*pitch = renderer->target->pitch;
    458 +	*format = renderer->target->format;
    459 +	return renderer->target->map;
    460 +}
    461 +
    462 +EXPORT
    463 +void
    464 +wld_target_unmap(struct wld_renderer *renderer)
    465 +{
    466 +	if (renderer->target)
    467 +		wld_unmap(renderer->target);
    468 +}
    469  
    470  /* https://en.wikipedia.org/wiki/Midpoint_circle_algorithm */
    471  static void
    472 @@ -286,6 +308,17 @@ wld_draw_text(struct wld_renderer *renderer,
    473  	                          extents);
    474  }
    475  
    476 +EXPORT
    477 +bool
    478 +wld_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y,
    479 +             uint32_t width, uint32_t height)
    480 +{
    481 +	if (!renderer->impl->set_clip)
    482 +		return false;
    483 +	renderer->impl->set_clip(renderer, x, y, width, height);
    484 +	return true;
    485 +}
    486 +
    487  EXPORT
    488  void
    489  wld_flush(struct wld_renderer *renderer)
    490 diff --git a/wld-private.h b/wld-private.h
    491 index 5a02630..c3d1a70 100644
    492 --- a/wld-private.h
    493 +++ b/wld-private.h
    494 @@ -69,12 +69,52 @@ struct glyph {
    495  	uint16_t advance;
    496  };
    497  
    498 +/* glyph indices of recently used characters, indexed by the character's
    499 + * low bits: FT_Get_Char_Index searches the face's cmap on every call */
    500 +#define FONT_CHAR_CACHE 256
    501 +
    502 +/* One character of UTF-8 text of at most len bytes into *c: its length,
    503 + * 0 at the end of the text or on a byte that starts no character. */
    504 +static inline int
    505 +wld_utf8_decode(const char *text, int len, uint32_t *c)
    506 +{
    507 +	const unsigned char *s = (const unsigned char *)text;
    508 +	int n, i;
    509 +
    510 +	if (len <= 0 || !s[0])
    511 +		return 0;
    512 +	if (s[0] < 0x80) {
    513 +		*c = s[0];
    514 +		return 1;
    515 +	}
    516 +	if ((s[0] & 0xe0) == 0xc0)
    517 +		n = 2, *c = s[0] & 0x1f;
    518 +	else if ((s[0] & 0xf0) == 0xe0)
    519 +		n = 3, *c = s[0] & 0x0f;
    520 +	else if ((s[0] & 0xf8) == 0xf0)
    521 +		n = 4, *c = s[0] & 0x07;
    522 +	else
    523 +		return 0;
    524 +	if (n > len)
    525 +		return 0;
    526 +	for (i = 1; i < n; i++) {
    527 +		if ((s[i] & 0xc0) != 0x80)
    528 +			return 0;
    529 +		*c = *c << 6 | (s[i] & 0x3f);
    530 +	}
    531 +	return n;
    532 +}
    533 +
    534  struct font {
    535  	struct wld_font base;
    536  
    537  	struct wld_font_context *context;
    538  	FT_Face face;
    539  	struct glyph **glyphs;
    540 +	struct {
    541 +		uint32_t key;
    542 +		FT_UInt index;
    543 +	} chars[FONT_CHAR_CACHE];
    544  };
    545  
    546  struct wld_context_impl {
    547 @@ -116,6 +156,8 @@ struct wld_renderer_impl {
    548  	                  struct font *font, uint32_t color,
    549  	                  int32_t x, int32_t y, const char *text, uint32_t length,
    550  	                  struct wld_extents *extents);
    551 +	void (*set_clip)(struct wld_renderer *renderer, int32_t x, int32_t y,
    552 +	                 uint32_t width, uint32_t height);
    553  	void (*flush)(struct wld_renderer *renderer);
    554  	void (*destroy)(struct wld_renderer *renderer);
    555  };
    556 @@ -156,6 +198,7 @@ struct buffer_socket_impl {
    557  };
    558  
    559  bool font_ensure_glyph(struct font *font, FT_UInt glyph_index);
    560 +FT_UInt font_char_index(struct font *font, uint32_t character);
    561  
    562  /**
    563   * Returns the number of bytes per pixel for the given format.
    564 diff --git a/wld.h b/wld.h
    565 index 8191ae3..0c90afd 100644
    566 --- a/wld.h
    567 +++ b/wld.h
    568 @@ -24,7 +24,9 @@
    569  #ifndef WLD_H
    570  #define WLD_H
    571  
    572 +#ifdef WLD_FONTCONFIG
    573  #include <fontconfig/fontconfig.h>
    574 +#endif
    575  #include <pixman.h>
    576  #include <stdbool.h>
    577  #include <stdint.h>
    578 @@ -90,6 +92,13 @@ void wld_destroy_context(struct wld_context *context);
    579  
    580  struct wld_extents {
    581  	uint32_t advance;
    582 +
    583 +	/**
    584 +	 * The box the glyphs cover, from the pen origin on the baseline.
    585 +	 * Only wld_font_text_extents sets it.
    586 +	 */
    587 +	int32_t ink_x, ink_y;
    588 +	uint32_t ink_width, ink_height;
    589  };
    590  
    591  struct wld_font {
    592 @@ -110,6 +119,16 @@ struct wld_font_context *wld_font_create_context();
    593   */
    594  void wld_font_destroy_context(struct wld_font_context *context);
    595  
    596 +/**
    597 + * Open a font file, face index of it (0 unless the file is a collection),
    598 + * pixel_size pixels tall. It needs no font matcher: this is how a font is
    599 + * opened where there is no fontconfig.
    600 + */
    601 +struct wld_font *wld_font_open_file(struct wld_font_context *context,
    602 +                                    const char *path, int index,
    603 +                                    double pixel_size);
    604 +
    605 +#ifdef WLD_FONTCONFIG
    606  /**
    607   * Open a new font from the given fontconfig match.
    608   */
    609 @@ -121,6 +140,7 @@ struct wld_font *wld_font_open_pattern(struct wld_font_context *context,
    610   */
    611  struct wld_font *wld_font_open_name(struct wld_font_context *context,
    612                                      const char *name);
    613 +#endif
    614  
    615  /**
    616   * Close a font.
    617 @@ -133,6 +153,11 @@ void wld_font_close(struct wld_font *font);
    618   */
    619  bool wld_font_ensure_char(struct wld_font *font, uint32_t character);
    620  
    621 +/**
    622 + * The character that draws the glyph called name, or 0.
    623 + */
    624 +uint32_t wld_font_char_by_name(struct wld_font *font, const char *name);
    625 +
    626  /**
    627   * Calculate the text extents of the given UTF-8 string.
    628   *
    629 @@ -258,6 +283,15 @@ void wld_blend_region(struct wld_renderer *renderer,
    630                        int32_t dst_x, int32_t dst_y,
    631                        pixman_region32_t *region);
    632  
    633 +/**
    634 + * The pixels of the renderer's target, for the CPU to read and write: what
    635 + * has been drawn so far, after every pending operation has finished. NULL
    636 + * when the target cannot be mapped. Unmap it before drawing again.
    637 + */
    638 +void *wld_target_map(struct wld_renderer *renderer, uint32_t *pitch,
    639 +                     uint32_t *format);
    640 +void wld_target_unmap(struct wld_renderer *renderer);
    641 +
    642  void wld_draw_circle(struct wld_renderer *renderer, uint32_t color,
    643  				int32_t x, int32_t y, uint32_t r, bool fill);
    644  
    645 @@ -272,6 +306,13 @@ void wld_draw_line(struct wld_renderer *renderer, uint32_t color,
    646   * @param extents   If not NULL, will be initialized to the extents of the
    647   *                  drawn text
    648   */
    649 +/**
    650 + * Limit drawing to a rectangle of the target. Setting a target resets it.
    651 + * Returns false when the renderer cannot clip.
    652 + */
    653 +bool wld_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y,
    654 +                  uint32_t width, uint32_t height);
    655 +
    656  void wld_draw_text(struct wld_renderer *renderer,
    657                     struct wld_font *font, uint32_t color,
    658                     int32_t x, int32_t y, const char *text, uint32_t length,