1#ifndef FASTUIDRAW_DEMO_TEXT_HELPER_HPP
2#define FASTUIDRAW_DEMO_TEXT_HELPER_HPP
3
4#include <vector>
5#include <set>
6#include <string>
7#include <iostream>
8#include <SDL_thread.h>
9#include <SDL_atomic.h>
10
11#include <fastuidraw/util/c_array.hpp>
12#include <fastuidraw/util/vecN.hpp>
13#include <fastuidraw/text/font_database.hpp>
14#include <fastuidraw/text/glyph_cache.hpp>
15#include <fastuidraw/text/font_freetype.hpp>
16#include <fastuidraw/painter/painter.hpp>
17
18#include "cast_c_array.hpp"
19
20inline
21std::ostream&
22operator<<(std::ostream &str, const fastuidraw::FontProperties &obj)
23{
24 str << obj.source_label() << "(foundry = " << obj.foundry()
25 << ", family = " << obj.family() << ", style = " << obj.style()
26 << ", bold = " << obj.bold() << ", italic = " << obj.italic()
27 << ")";
28 return str;
29}
30
31class GlyphSetGenerator
32{
33public:
34 static
35 void
36 generate(unsigned int num_threads,
37 fastuidraw::GlyphRenderer r,
38 fastuidraw::reference_counted_ptr<const fastuidraw::FontBase> f,
39 std::vector<fastuidraw::Glyph> &dst,
40 fastuidraw::GlyphCache &glyph_cache,
41 std::vector<int> &cnts);
42
43private:
44 GlyphSetGenerator(fastuidraw::GlyphRenderer r,
45 fastuidraw::reference_counted_ptr<const fastuidraw::FontBase> f,
46 std::vector<fastuidraw::Glyph> &dst);
47
48 static
49 int
50 execute(void *ptr);
51
52 fastuidraw::GlyphRenderer m_render;
53 fastuidraw::reference_counted_ptr<const fastuidraw::FontBase> m_font;
54 fastuidraw::c_array<fastuidraw::Glyph> m_dst;
55 SDL_atomic_t m_counter;
56};
57
58/*
59 * \param[out] out_sequence sequence to which to add glyphs
60 * \param glyph_codes sequence of glyph codes (not characater codes!)
61 * \param font font of the glyphs
62 * \param shift_by amount by which to shit all glyphs
63 */
64void
65create_formatted_text(fastuidraw::GlyphSequence &out_sequence,
66 const std::vector<uint32_t> &glyph_codes,
67 const fastuidraw::FontBase *font,
68 const fastuidraw::vec2 &shift_by = fastuidraw::vec2(0.0f, 0.0f));
69
70
71/*
72 * \param[out] out_sequence sequence to which to add glyphs
73 * \param stream input stream from which to grab lines of text
74 * \param font font of the glyphs
75 * \param font_database used to select glyphs from font
76 * \param shift_by amount by which to shit all glyphs
77 */
78void
79create_formatted_text(fastuidraw::GlyphSequence &out_sequence,
80 enum fastuidraw::Painter::screen_orientation,
81 std::istream &stream,
82 const fastuidraw::FontBase *font,
83 fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> font_database,
84 const fastuidraw::vec2 &shift_by = fastuidraw::vec2(0.0f, 0.0f));
85
86/*
87 * \param[out] out_run run to which to add glyphs
88 * \param stream input stream from which to grab lines of text
89 * \param font font of the glyphs
90 * \param font_database used to select glyphs from font
91 * \param shift_by amount by which to shit all glyphs
92 */
93void
94create_formatted_text(fastuidraw::GlyphRun &out_run,
95 enum fastuidraw::Painter::screen_orientation,
96 std::istream &stream,
97 const fastuidraw::FontBase *font,
98 fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> font_database,
99 const fastuidraw::vec2 &shift_by = fastuidraw::vec2(0.0f, 0.0f));
100
101void
102add_fonts_from_path(const std::string &path,
103 fastuidraw::reference_counted_ptr<fastuidraw::FreeTypeLib> lib,
104 fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> font_database);
105
106void
107add_fonts_from_font_config(fastuidraw::reference_counted_ptr<fastuidraw::FreeTypeLib> lib,
108 fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> font_database);
109
110fastuidraw::reference_counted_ptr<const fastuidraw::FontBase>
111select_font_font_config(int weight, int slant,
112 fastuidraw::c_string style,
113 fastuidraw::c_string family,
114 fastuidraw::c_string foundry,
115 const std::set<std::string> &langs,
116 fastuidraw::reference_counted_ptr<fastuidraw::FreeTypeLib> lib,
117 fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> font_database);
118
119fastuidraw::c_string
120default_font(void);
121
122fastuidraw::c_string
123default_font_path(void);
124
125#endif
126