lace_opengl_0.1.0_672a6415/source/lean/text/opengl-font.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
with
     openGL.Glyph.Container,
     openGL.FontImpl,

     freetype.Face,
     freetype_c.FT_GlyphSlot,

     ada.Containers.hashed_Maps;

package openGL.Font
--
--  Specific font classes are derived from this class. It uses the helper
--  classes 'freetype_c.Face' and 'freetype_c.FTSize' to access the Freetype library.
--
--  This class is abstract and derived classes must implement the protected
--  'MakeGlyph' function to create glyphs of the appropriate type.
--
is
   type Item is abstract tagged limited private;
   type View is access all Item'Class;


   ----------
   -- Font_Id
   --

   type font_Id is
      record
         Name : asset_Name;
         Size : Integer;
      end record;

   function Hash (the_Id : in font_Id) return ada.Containers.Hash_type;



   ------------
   -- Font Maps
   --
   package font_id_Maps_of_font is new ada.Containers.hashed_Maps (Key_Type        => font_Id,
                                                                   Element_Type    => Font.view,
                                                                   Hash            => Hash,
                                                                   Equivalent_Keys => "=");
   subtype font_id_Map_of_font  is font_id_Maps_of_font.Map;


   ---------
   --  Forge
   --

   procedure destruct (Self : in out Item);
   procedure free     (Self : in out View);


   --------------
   --  Attributes
   --

   function CharMap (Self : in Item;   Encoding : in freetype_c.FT_Encoding) return Boolean;
   --
   --  Set the character map for the face.
   --
   --  Encoding: Freetype enumerate for char map code.
   --
   --  Returns True if charmap was valid and set correctly.


   function CharMapCount (Self : in Item) return Natural;
   --
   --  Get the number of character maps in this face.
   --
   --  Returns the character map count.


   function CharMapList (Self : access Item) return freetype.face.FT_Encodings_view;
   --
   --  Get a list of character maps in this face.
   --
   --  Returns aceess to the array of encodings.


   function Ascender (Self : in Item) return Real;
   --
   --  Get the global ascender height for the face.
   --
   --  Returns the Ascender height.


   function Descender (Self : in Item) return Real;
   --
   --  Gets the global descender height for the face.
   --
   --  Returns the Descender height.


   function  LineHeight  (Self : in Item) return Real;
   --
   --  Gets the line spacing for the font.
   --
   --  Returns the line height.


   function FaceSize (Self : access Item;   size         : in Natural;
                                            x_Res, y_Res : in Natural) return Boolean;
   --
   --  Set the character size for the current face.
   --
   --  Returns True if size was set correctly.


   function FaceSize (Self : in Item) return Natural;
   --
   --  Get the current face size in points (1/72 inch).
   --
   --  Returns the face size.


   procedure Depth (Self : in out Item;   Depth : in Real);
   --
   --  Set the extrusion distance for the font. Only implemented by FTExtrudeFont.
   --
   --  Depth: The extrusion distance.


   procedure Outset (Self : in out Item;   Outset : in Real);
   --
   --  Set the outset distance for the font. Only implemented by FTOutlineFont, FTPolygonFont and FTExtrudeFont.
   --
   --  Outset: The outset distance.


   procedure Outset (Self : in out Item;   Front : in Real;
                                           Back  : in Real);
   --
   --  Set the front and back outset distances for the font. Only implemented by FTExtrudeFont.
   --
   --  Front: The front outset distance.
   --  Back:  The  back outset distance.


   function BBox (Self : access Item;   Text     : in String;
                                        Length   : in Integer  := -1;
                                        Position : in Vector_3 := Origin_3D;
                                        Spacing  : in Vector_3 := Origin_3D) return Bounds;
   --
   --  Get the bounding box for a string.
   --
   --  Text:     A character buffer.
   --  Length:   The length of the string. If < 0 then all characters will be checked until a null character is encountered.
   --  Position: The pen position of the first character.
   --  Spacing:  A displacement vector to add after each character has been checked.
   --
   --  Returns the corresponding bounding box.


   function Error (Self : in Item) return freetype_c.FT_Error;
   --
   --  Queries the font for errors.
   --
   --  Returns the current error code.


   --------------
   --  Operations
   --

   function attach (Self : in Item;   Font_File_Path : in String) return Boolean;
   --
   --  Attach auxilliary file to font e.g font metrics.
   --  Note: Not all font formats implement this function.
   --
   --  fontFilePath: The auxilliary font file path.
   --
   --  Returns True if file has been attached successfully.


   function attach (Self : in Item;   pBufferBytes      : in FontImpl.unsigned_char_Pointer;
                                      bufferSizeInBytes : in Natural) return Boolean;
   --
   --  Attach auxilliary data to font e.g font metrics, from memory.
   --  Note: Not all font formats implement this function.
   --
   --  'pBufferBytes'          The in-memory buffer.
   --  'bufferSizeInBytes'     The length of the buffer in bytes.
   --
   --  Returns True if file has been attached successfully.


   procedure glyph_load_Flags (Self : in out Item;   Flags : in freetype_c.FT_Int);
   --
   --  Set the glyph loading flags. By default, fonts use the most
   --  sensible flags when loading a font's glyph using FT_Load_Glyph().
   --  This function allows to override the default flags.
   --
   --  Flags: The glyph loading flags.


   function Advance (Self : access Item;   Text    : in String;
                                           Length  : in Integer  := -1;
                                           Spacing : in Vector_3 := Origin_3D) return Real;
   --
   --  Get the advance for a string.
   --
   --  Text:    String to be checked.
   --  Length:  The length of the string. If < 0 then all characters will be checked until
   --           a null character is encountered.
   --  Spacing: A displacement vector to add after each character has been checked.
   --
   --  Returns the string's advance width.


   function kern_Advance (Self : in Item;    From, To : in Character) return Real;

   function x_PPEM  (Self : in Item) return Real;
   function x_Scale (Self : in Item) return Real;
   function y_Scale (Self : in Item) return Real;

   function check_Glyphs (Self : access Item;   Text     : in String;
                                                Length   : in Integer             := -1;
                                                Position : in Vector_3            := math.Origin_3D;
                                                Spacing  : in Vector_3            := math.Origin_3D;
                                                Mode     : in fontImpl.RenderMode := fontImpl.RENDER_ALL) return Vector_3;
   --
   --  Render a string of characters.
   --
   --  Text:     String to be output.
   --  Length:   The length of the string. If < 0 then all characters will be displayed until a null character is encountered.
   --  Position: The pen position of the first character.
   --  Spacing:  A displacement vector to add after each character has been displayed
   --  Mode:     Render mode to use for display.
   --
   --  Returns the new pen position after the last character was output.


   function MakeGlyph (Self : access Item;   Slot : in freetype_c.FT_GlyphSlot.item) return glyph.Container.Glyph_view
                       is abstract;
   --
   --  Construct a glyph of the correct type.
   --  Clients must override the function and return their specialised glyph.
   --
   --  Slot: A FreeType glyph slot.
   --
   --  Returns an FTGlyph or null on failure.



private

   type Item is abstract tagged limited
      record
         Impl : FontImpl.view;      -- Internal FTGL FTFont implementation object. For private use only.
      end record;


   procedure define (Self : in out Item;   fontFilePath : in String);
   --
   --  Open and read a font file. Sets Error flag.


   procedure define (Self : in out Item;   pBufferBytes      : in FontImpl.unsigned_char_Pointer;
                                           bufferSizeInBytes : in Natural);
   --
   --  Open and read a font from a buffer in memory. Sets Error flag.
   --  The buffer is owned by the client and is NOT copied by FTGL. The pointer must be valid while using FTGL.


   procedure define (Self : in out Item;   pImpl : in FontImpl.view);
   --
   --  Internal FTGL FTFont constructor. For private use only.
   --
   --  pImpl: An internal implementation object, which will be destroyed upon FTFont deletion.


end openGL.Font;