Euphoria
loadedfont.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 
5 #include <map>
6 
7 #include "core/image.h"
8 
9 
10 namespace eu::io
11 {
12  struct FileSystem;
13  struct FilePath;
14 }
15 
16 
17 namespace eu::core
18 {
19  // This represents a loaded glyph not yet placed on a texture image
20  struct LoadedGlyph
21  {
22  //
23  // width_
24  // <--------->
25  // +---------+
26  // bearingX | | | |
27  // -------> | | | bearingY |
28  // origin | | | | height
29  // X.........|.........|....... baseline |
30  // | | |
31  // | | |
32  // +---------+
33  //
34  // ------------------------------> advance (x to next glyph)
35  //
36 
37  bool valid = false;
38  int code_point = 0;
39  int bearing_x = 0;
40  int bearing_y = 0;
41  int advance = 0;
43  float size = 0.0f;
44  };
45 
46 
47  using KerningMap = std::map<std::pair<int, int>, float>;
48 
49 
50  // represent a loaded font (or a part), but it not yet been converted
51  // into a renderable data and texture.
52  struct LoadedFont
53  {
54  std::map<int, LoadedGlyph> codepoint_to_glyph;
56  std::map<std::string, int> private_use_aliases;
57  int next_private_use = 0xE000;
58  int line_height = -1;
59 
60  int
61  generate_new_index_from_private_use(const std::string& alias);
62 
63  void
64  combine_with(const LoadedFont& fc);
65  };
66 
67 
70 
71 
74 
75 
78  (
79  io::FileSystem* file_system,
80  const io::FilePath& font_file,
81  int font_size,
82  const std::string& chars
83  );
84 
85 
88  (
89  std::shared_ptr<MemoryChunk> file_memory,
90  int font_size,
91  const std::string& chars
92  );
93 
96  (
97  io::FileSystem* fs,
98  const io::FilePath& image_file,
99  const std::string& image_alias,
100  float image_scale,
101  float image_bearing_x,
102  float image_bearing_y,
103  float image_advance
104  );
105 
106  LoadedFont
108  (
109  const Image& image,
110  const std::string& image_alias,
111  float image_scale,
112  float image_bearing_x,
113  float image_bearing_y,
114  float image_advance
115  );
116 }
117 
LoadedFont get_characters_from_single_image(io::FileSystem *fs, const io::FilePath &image_file, const std::string &image_alias, float image_scale, float image_bearing_x, float image_bearing_y, float image_advance)
Definition: loadedfont.cc:391
std::map< std::pair< int, int >, float > KerningMap
Definition: loadedfont.h:47
LoadedFont get_characters_from_font(io::FileSystem *file_system, const io::FilePath &font_file, int font_size, const std::string &chars)
Definition: loadedfont.cc:299
LoadedFont load_characters_from_builtin13()
Definition: loadedfont.cc:244
LoadedFont load_characters_from_builtin8()
Definition: loadedfont.cc:285
Definition: enum.h:8
int generate_new_index_from_private_use(const std::string &alias)
Definition: loadedfont.cc:133
void combine_with(const LoadedFont &fc)
Definition: loadedfont.cc:144
std::map< int, LoadedGlyph > codepoint_to_glyph
Definition: loadedfont.h:54
KerningMap kerning
Definition: loadedfont.h:55
std::map< std::string, int > private_use_aliases
Definition: loadedfont.h:56
core::Image image
Definition: loadedfont.h:42