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

  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
with
     ada.unchecked_Deallocation,
     ada.unchecked_Conversion;

package body openGL.Font
is
   -----------
   --  Utility
   --

   function Hash (the_Id : in font_Id) return ada.Containers.Hash_type
   is
      use ada.Containers;
   begin
      return Hash (the_Id.Name) + Hash_type (the_Id.Size);
   end Hash;


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

   procedure define (Self : in out Item;   fontFilePath : in String)
   is
   begin
      Self.Impl := new FontImpl.item;
      Self.Impl.define (Self'Access, fontFilePath);
   end define;


   procedure define (Self : in out Item;   pBufferBytes      : in FontImpl.unsigned_char_Pointer;
                                           bufferSizeInBytes : in Natural)
   is
   begin
      Self.Impl := new FontImpl.item;
      Self.Impl.define (Self'Access, pBufferBytes, bufferSizeInBytes);
   end define;


   procedure define (Self : in out Item;   pImpl : in FontImpl.view)
   is
   begin
      Self.Impl := pImpl;
   end define;


   procedure destruct (Self : in out Item)
   is
      procedure free is new ada.unchecked_Deallocation (FontImpl.item'Class,
                                                        FontImpl.view);
   begin
      Self.Impl.destruct;
      free (Self.Impl);
   end destruct;


   procedure free (Self : in out View)
   is
      procedure deallocate is new ada.unchecked_Deallocation (Item'Class, View);
   begin
      Self.destruct;
      deallocate (Self);
   end free;


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

   function CharMap (Self : in Item;   Encoding : in freetype_c.FT_Encoding) return Boolean
   is
   begin
      return Self.impl.CharMap (Encoding);
   end CharMap;


   function CharMapCount (Self : in Item) return Natural
   is
   begin
      return Self.impl.CharMapCount;
   end CharMapCount;


   function CharMapList (Self : access Item) return freetype.face.FT_Encodings_view
   is
   begin
      return Self.impl.CharMapList;
   end CharMapList;


   function Ascender (Self : in Item) return Real
   is
   begin
      return Self.impl.Ascender;
   end Ascender;


   function Descender (Self : in Item) return Real
   is
   begin
      return Self.impl.Descender;
   end Descender;


   function LineHeight (Self : in Item) return Real
   is
   begin
      return Self.impl.LineHeight;
   end LineHeight;


   function FaceSize (Self : access Item;   Size          : in Natural;
                                            x_Res, y_Res  : in Natural) return Boolean
   is
   begin
      return Self.impl.FaceSize (Size, x_Res, y_Res);
   end FaceSize;


   function FaceSize (Self : in Item) return Natural
   is
   begin
      return Self.impl.FaceSize;
   end FaceSize;


   procedure Depth (Self : in out Item;   Depth : in Real)
   is
   begin
      Self.impl.Depth (Depth);
   end Depth;


   procedure Outset (Self : in out Item;   Outset : in Real)
   is
   begin
      Self.impl.Outset (Outset);
   end Outset;


   procedure Outset (Self : in out Item;   Front : in Real;
                                           Back  : in Real)
   is
   begin
      Self.impl.Outset (Front, Back);
   end Outset;


   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
   is
   begin
      return Self.impl.BBox (Text, Length, Position, Spacing);
   end BBox;


   function Error (Self : in Item) return freetype_c.FT_Error
   is
   begin
      return Self.impl.Err;
   end Error;


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

   function attach (Self : in Item;   Font_File_Path : in String) return Boolean
   is
   begin
      return Self.impl.attach (Font_File_Path);
   end Attach;


   function attach (Self : in Item;   pBufferBytes      : in FontImpl.unsigned_char_Pointer;
                                      bufferSizeInBytes : in Natural) return Boolean
   is
   begin
      return Self.impl.Attach (pBufferBytes, bufferSizeInBytes);
   end Attach;


   procedure glyph_load_Flags (Self : in out Item;   Flags : in freetype_c.FT_Int)
   is
   begin
      Self.impl.GlyphLoadFlags (Flags);
   end glyph_load_Flags;


   function Advance (Self : access Item;   Text    : in String;
                                           Length  : in Integer  := -1;
                                           Spacing : in Vector_3 := Origin_3D) return Real
   is
   begin
      return Self.impl.Advance (Text, Length, Spacing);
   end Advance;


   function kern_Advance (Self : in Item;   From, To : in Character) return Real
   is
   begin
      return Self.impl.kern_Advance (From, To);
   end kern_Advance;


   function x_PPEM (Self : in Item) return Real
   is
   begin
      return Self.impl.x_PPEM;
   end x_PPEM;


   function x_Scale (Self : in Item) return Real
   is
   begin
      return Self.impl.x_Scale;
   end x_Scale;


   function y_Scale (Self : in Item) return Real
   is
   begin
      return Self.impl.y_Scale;
   end y_Scale;


   function check_Glyphs (Self : access Item;   Text     : in String;
                                                Length   : in Integer             := -1;
                                                Position : in Vector_3            := Origin_3D;
                                                Spacing  : in Vector_3            := Origin_3D;
                                                Mode     : in fontImpl.RenderMode := fontImpl.RENDER_ALL) return Vector_3
   is
      function to_Integer is new ada.Unchecked_Conversion (fontImpl.RenderMode, Integer);
   begin
      return Self.impl.Render (Text,
                               Length,
                               Position,
                               Spacing,
                               to_Integer (Mode));
   end check_Glyphs;


end openGL.Font;