00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUFO_TEXTSTREAM_H
00019 #define CUFO_TEXTSTREAM_H
00020
00021 #include <cufo/stream.h>
00022 #include <cufo/sink.h>
00023
00024 CU_BEGIN_DECLARATIONS
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 struct cufo_textsink
00035 {
00036 cu_inherit (cutext_sink);
00037 cutext_sink_t subsink;
00038
00039 struct cu_buffer buf;
00040 struct cu_buffer buf_markup;
00041 int buffered_width;
00042
00043 cufo_textstyle_t style;
00044
00045 int tabstop;
00046 int left_margin;
00047 int right_margin;
00048 int cont_indent;
00049 cu_wstring_t cont_eol_insert;
00050 cu_wstring_t cont_bol_insert;
00051
00052 cu_bool_t is_cont : 1;
00053 size_t input_pos;
00054 };
00055
00056 CU_SINLINE int
00057 cufo_textsink_width(cufo_textsink_t sink)
00058 { return sink->right_margin - sink->left_margin; }
00059
00060 void cufo_textsink_block_boundary(cufo_textsink_t sink);
00061
00062
00063 struct cufo_textstyler
00064 {
00065
00066 cu_inherit (cucon_hzmap_node);
00067 cu_word_t tag;
00068
00069
00070 cu_wstring_t (*enter)(cufo_textsink_t sink, cufo_tag_t tag,
00071 cufo_attrbind_t attrbinds);
00072 cu_wstring_t (*leave)(cufo_textsink_t sink, cufo_tag_t tag);
00073 };
00074
00075
00076 struct cufo_textstyle
00077 {
00078 size_t sink_size;
00079 cu_clop(sink_init, void, cufo_textsink_t sink);
00080 struct cucon_hzmap tag_to_styler;
00081 cu_wstring_t (*default_enter)(cufo_textsink_t sink, cufo_tag_t tag,
00082 cufo_attrbind_t attrbinds);
00083 cu_wstring_t (*default_leave)(cufo_textsink_t sink, cufo_tag_t tag);
00084 };
00085
00086
00087
00088
00089
00090
00091 void cufo_textstyle_init(cufo_textstyle_t style, size_t sink_size,
00092 cu_clop(sink_init, void, cufo_textsink_t));
00093
00094
00095
00096
00097
00098
00099
00100 #define CUFO_TEXTSTYLER_STATIC(name) \
00101 static struct cufo_textstyler name##_styler \
00102 = {CUCON_HZMAP_NODE_INIT, 0, name##_enter, name##_leave}
00103
00104
00105
00106
00107 void cufo_textstyle_bind_static(cufo_textstyle_t style,
00108 cufo_tag_t tag, cufo_textstyler_t styler);
00109
00110 struct cufo_textstyle cufoP_default_textstyle;
00111
00112 CU_SINLINE cufo_textstyle_t
00113 cufo_default_textstyle(void)
00114 { return &cufoP_default_textstyle; }
00115
00116
00117 CU_END_DECLARATIONS
00118
00119 #endif