taisei/src/resource/font.h

123 lines
2.7 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
2018-01-04 18:14:31 +01:00
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
*/
2017-09-27 14:14:53 +02:00
#pragma once
#include "taisei.h"
#include "sprite.h"
2017-12-14 04:48:30 +01:00
#include "hashtable.h"
#include "resource.h"
#include "renderer/api.h"
typedef enum {
ALIGN_LEFT = 0, // must be 0
ALIGN_CENTER,
ALIGN_RIGHT,
} Alignment;
typedef ulong charcode_t;
2017-12-14 04:48:30 +01:00
typedef struct Font Font;
typedef struct FontMetrics {
int ascent;
int descent;
int max_glyph_height;
int lineskip;
double scale;
} FontMetrics;
typedef struct GlyphMetrics {
int bearing_x;
int bearing_y;
int width;
int height;
int advance;
} GlyphMetrics;
// TODO: maybe move this into util/geometry.h
typedef struct BBox {
struct {
int min;
int max;
} x;
struct {
int min;
int max;
} y;
} BBox;
typedef void (*GlyphDrawCallback)(Font *font, charcode_t charcode, SpriteParams *spr_params, void *userdata);
typedef struct TextParams {
const char *font;
Font *font_ptr;
const char *shader;
ShaderProgram *shader_ptr;
struct {
GlyphDrawCallback func;
void *userdata;
} glyph_callback;
struct { double x, y; } pos;
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
const Color *color;
const ShaderCustomParams *shader_params;
Texture *aux_textures[NUM_SPRITE_AUX_TEXTURES];
BlendMode blend;
Alignment align;
} TextParams;
Font* get_font(const char *font)
attr_nonnull(1);
ShaderProgram* text_get_default_shader(void)
attr_returns_nonnull;
const FontMetrics* font_get_metrics(Font *font)
attr_nonnull(1) attr_returns_nonnull;
double font_get_lineskip(Font *font)
attr_nonnull(1);
const GlyphMetrics* font_get_char_metrics(Font *font, charcode_t c)
attr_nonnull(1);
double text_draw(const char *text, const TextParams *params)
attr_nonnull(1, 2);
double text_draw_wrapped(const char *text, double max_width, const TextParams *params)
attr_nonnull(1, 3);
void text_render(const char *text, Font *font, Sprite *out_sprite, BBox *out_bbox)
attr_nonnull(1, 2, 3, 4);
void text_shorten(Font *font, char *text, double width)
attr_nonnull(1, 2);
void text_wrap(Font *font, const char *src, double width, char *buf, size_t bufsize)
attr_nonnull(1, 2, 4);
void text_bbox(Font *font, const char *text, uint maxlines, BBox *bbox)
attr_nonnull(1, 2, 4);
int text_width_raw(Font *font, const char *text, uint maxlines)
attr_nonnull(1, 2);
double text_width(Font *font, const char *text, uint maxlines)
attr_nonnull(1, 2);
int text_height_raw(Font *font, const char *text, uint maxlines)
attr_nonnull(1, 2);
double text_height(Font *font, const char *text, uint maxlines)
attr_nonnull(1, 2);
extern ResourceHandler font_res_handler;
#define FONT_PATH_PREFIX "res/fonts/"
#define FONT_EXTENSION ".font"