citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

gl_font.h (1905B)


      1 /*
      2  * Copyright 2012 Google, Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  * Google Author(s): Behdad Esfahbod
     17  */
     18 
     19 #ifndef GL_FONT_H
     20 #define GL_FONT_H
     21 
     22 #include <unordered_map>
     23 
     24 #include "demo-common.h"
     25 #include "gl_atlas.h"
     26 
     27 #include <ft2build.h>
     28 #include FT_FREETYPE_H
     29 
     30 
     31 namespace citrun {
     32 
     33 typedef struct {
     34 	glyphy_extents_t extents;
     35 	double		advance;
     36 	glyphy_bool_t	is_empty; /* has no outline; eg. space; don't draw it */
     37 	unsigned int	nominal_w;
     38 	unsigned int	nominal_h;
     39 	unsigned int	atlas_x;
     40 	unsigned int	atlas_y;
     41 } glyph_info_t;
     42 
     43 class gl_font {
     44 	FT_Library	 ft_library;
     45 	FT_Face		 face;
     46 
     47 	std::unordered_map<unsigned int, glyph_info_t> glyph_cache;
     48 
     49 	/* stats */
     50 	unsigned int	 num_glyphs;
     51 	double		 sum_error;
     52 	unsigned int	 sum_endpoints;
     53 	double		 sum_fetch;
     54 	unsigned int	 sum_bytes;
     55 
     56 	citrun::gl_atlas &atlas;
     57 	glyphy_arc_accumulator_t *acc;
     58 
     59 	void		 _upload_glyph(unsigned int, glyph_info_t *);
     60 	void		 encode_ft_glyph(unsigned int,
     61 				double,
     62 				glyphy_rgba_t *,
     63 				unsigned int,
     64 				unsigned int *,
     65 				unsigned int *,
     66 				unsigned int *,
     67 				glyphy_extents_t *,
     68 				double *);
     69 public:
     70 			 gl_font(std::string const&, citrun::gl_atlas &);
     71 			~gl_font();
     72 
     73 	FT_Face		 get_face() const;
     74 	citrun::gl_atlas &get_atlas();
     75 	void		 lookup_glyph(unsigned int, glyph_info_t *);
     76 	void		 print_stats();
     77 };
     78 
     79 } // namespace citrun
     80 #endif /* GL_FONT_H */