libsf3
Loading...
Searching...
No Matches
sf3_text.h
Go to the documentation of this file.
1#ifndef __SF3_TEXT__
2#define __SF3_TEXT__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_TEXT 0x08
7
33
40 uint64_t start;
43 uint64_t end;
46 uint8_t option_type;
47};
48
51 struct sf3_markup markup;
53 float r;
55 float g;
57 float b;
58};
59
62 struct sf3_markup markup;
64 float size;
65};
66
69 struct sf3_markup markup;
71 uint8_t level;
72};
73
81
88
95
100 struct sf3_identifier identifier;
102 uint64_t markup_size;
104 uint32_t markup_count;
106 struct sf3_markup markup[];
107};
108
113SF3_INLINE const struct sf3_markup *sf3_text_next_markup(const struct sf3_markup *markup){
114 const char *base = (char*)markup;
115 switch(markup->option_type){
116 case SF3_MARKUP_BOLD:
120 case SF3_MARKUP_MONO:
121 return (struct sf3_markup *) (base+sizeof(struct sf3_markup));
122 case SF3_MARKUP_COLOR:
123 return (struct sf3_markup *) (base+sizeof(struct sf3_markup_color));
124 case SF3_MARKUP_SIZE:
125 return (struct sf3_markup *) (base+sizeof(struct sf3_markup_size));
127 return (struct sf3_markup *) (base+sizeof(struct sf3_markup_heading));
128 case SF3_MARKUP_LINK:
129 return (struct sf3_markup *) SF3_SKIP_STR(((struct sf3_markup_link *)markup)->address);
131 return (struct sf3_markup *) SF3_SKIP_STR(((struct sf3_markup_target *)markup)->address);
132 case SF3_MARKUP_FONT:
133 return (struct sf3_markup *) SF3_SKIP_STR(((struct sf3_markup_font *)markup)->font);
134 default:
135 return 0;
136 }
137}
138
140SF3_INLINE const char *sf3_text_string(const struct sf3_text *text){
141 const char *base = (char *)text->markup;
142 base += text->markup_size;
143 return ((sf3_str64*)base)->str;
144}
145
148 switch(type){
149 case SF3_MARKUP_BOLD: return "bold";
150 case SF3_MARKUP_ITALIC: return "italic";
151 case SF3_MARKUP_UNDERLINE: return "underline";
152 case SF3_MARKUP_STRIKE: return "strike";
153 case SF3_MARKUP_MONO: return "mono";
154 case SF3_MARKUP_COLOR: return "color";
155 case SF3_MARKUP_SIZE: return "size";
156 case SF3_MARKUP_HEADING: return "heading";
157 case SF3_MARKUP_LINK: return "link";
158 case SF3_MARKUP_TARGET: return "target";
159 case SF3_MARKUP_FONT: return "font";
160 default: return "Unknown";
161 }
162}
163
165SF3_EXPORT size_t sf3_text_size(const struct sf3_text *text){
166 const char *base = (char *)text->markup;
167 base += text->markup_size;
168 const sf3_str64 *str = ((sf3_str64*)base);
169 const void *start = (const void *)text;
170 const void *end = (const void *)(str->str+str->length);
171 return (end-start);
172}
173#endif
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
#define SF3_SKIP_STR(STR)
Macro to retrieve a pointer past the variable size of an SF3 string.
Definition sf3_core.h:59
SF3_INLINE const char * sf3_text_string(const struct sf3_text *text)
Returns the raw textual contents.
Definition sf3_text.h:140
SF3_INLINE const struct sf3_markup * sf3_text_next_markup(const struct sf3_markup *markup)
Definition sf3_text.h:113
sf3_markup_option_type
The possible markup option types.
Definition sf3_text.h:9
@ SF3_MARKUP_ITALIC
The option marks italicisation.
Definition sf3_text.h:13
@ SF3_MARKUP_UNDERLINE
The option marks underlining.
Definition sf3_text.h:15
@ SF3_MARKUP_TARGET
The option marks a link target and is a sf3_markup_target.
Definition sf3_text.h:29
@ SF3_MARKUP_HEADING
The option marks a heading and is a sf3_markup_heading.
Definition sf3_text.h:25
@ SF3_MARKUP_COLOR
The option marks color and is a sf3_markup_color.
Definition sf3_text.h:21
@ SF3_MARKUP_SIZE
The option marks font size and is a sf3_markup_size.
Definition sf3_text.h:23
@ SF3_MARKUP_FONT
The option marks a font switch and is a sf3_markup_font.
Definition sf3_text.h:31
@ SF3_MARKUP_BOLD
The option marks bolding.
Definition sf3_text.h:11
@ SF3_MARKUP_MONO
The option marks monospacing.
Definition sf3_text.h:19
@ SF3_MARKUP_STRIKE
The option marks strikethrough.
Definition sf3_text.h:17
@ SF3_MARKUP_LINK
The option marks a hyperlink and is a sf3_markup_link.
Definition sf3_text.h:27
SF3_EXPORT const char * sf3_text_markup_option_type(enum sf3_markup_option_type type)
Returns a human-readable string description of the markup option.
Definition sf3_text.h:147
SF3_EXPORT size_t sf3_text_size(const struct sf3_text *text)
Computes the size of the text file in bytes.
Definition sf3_text.h:165
The basic header structure of every SF3 file.
Definition sf3_core.h:70
Description of a color change.
Definition sf3_text.h:50
float g
The green channel, in the range of [0,1].
Definition sf3_text.h:55
float r
The red channel, in the range of [0,1].
Definition sf3_text.h:53
float b
The blue channel, in the range of [0,1].
Definition sf3_text.h:57
Description of a font family change.
Definition sf3_text.h:90
sf3_str16 font
The name of the font-family to select.
Definition sf3_text.h:93
Description of a heading.
Definition sf3_text.h:68
uint8_t level
The level of the heading as a positive integer.
Definition sf3_text.h:71
struct sf3_markup markup
Definition sf3_text.h:69
Description of a font size change.
Definition sf3_text.h:61
float size
The size of the font in em units.
Definition sf3_text.h:64
Description of a link target.
Definition sf3_text.h:83
sf3_str16 address
The address of this target.
Definition sf3_text.h:86
uint64_t start
Definition sf3_text.h:40
uint8_t option_type
Definition sf3_text.h:46
uint64_t end
Definition sf3_text.h:43
char str[]
Definition sf3_core.h:55
uint64_t length
Definition sf3_core.h:54
struct sf3_markup markup[]
The markup options.
Definition sf3_text.h:106
uint32_t markup_count
The number of markup options stored.
Definition sf3_text.h:104
uint64_t markup_size
The size of the markup options in bytes.
Definition sf3_text.h:102