Back to index

texmacs  1.0.7.15
bitmap_font.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bitmap_font.hpp
00004 * DESCRIPTION: bitmap fonts
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef BITMAP_FONT_H
00013 #define BITMAP_FONT_H
00014 #include "resource.hpp"
00015 
00016 RESOURCE(font_metric);
00017 RESOURCE(font_glyphs);
00018 
00019 typedef int SI;
00020 typedef unsigned char QN;
00021 
00022 struct metric_struct {
00023   SI x1, y1;
00024   SI x2, y2;
00025   SI x3, y3;
00026   SI x4, y4;
00027 };
00028 
00029 typedef metric_struct metric[1];
00030 
00031 /******************************************************************************
00032 * The glyph structure
00033 ******************************************************************************/
00034 
00035 struct glyph_rep: concrete_struct {
00036   short depth;               // number of bits per pixel >= depth
00037   short width, height;       // width and height in pixels
00038   short xoff, yoff;          // offset of origin
00039   short lwidth;              // logical width of character
00040   short status;              // status for extensible characters
00041   QN*   raster;              // character definition
00042 
00043   glyph_rep (int w, int h, int xoff, int yoff, int depth, int status=0);
00044   ~glyph_rep ();
00045   inline int  get_1 (int i, int j);
00046   inline void set_1 (int i, int j, int with);
00047   int  get_x (int i, int j);
00048   void set_x (int i, int j, int with);
00049   int  get (int i, int j);
00050   void set (int i, int j, int with);
00051   void adjust_bot ();
00052   void adjust_top ();
00053 };
00054 
00055 struct glyph {
00056   CONCRETE_NULL(glyph);
00057   glyph (int w2, int h2, int xoff2, int yoff2, int depth2=1, int status2= 0);
00058 };
00059 CONCRETE_NULL_CODE(glyph);
00060 
00061 inline int
00062 glyph_rep::get_1 (int i, int j) {
00063   int bit= j*width+i;
00064   return (raster[bit>>3] >> (bit&7)) & 1;
00065 }
00066 
00067 inline void
00068 glyph_rep::set_1 (int i, int j, int with) {
00069   int bit= j*width+i;
00070   if (with==0) raster[bit>>3] &= ~(1 << (bit&7));
00071   else raster[bit>>3] |= (1 << (bit&7));
00072 }
00073 
00074 tm_ostream& operator << (tm_ostream& out, glyph gl);
00075 
00076 glyph shrink     (glyph gl, int xf, int yf, SI& xo, SI& yo);
00077 glyph join       (glyph gl1, glyph gl2);
00078 glyph glue       (glyph gl1, glyph gl2);
00079 glyph add        (glyph gl1, glyph gl2);
00080 glyph move       (glyph gl, SI x, SI y);
00081 glyph clip       (glyph gl, SI x1, SI y1, SI x2, SI y3);
00082 glyph hor_flip   (glyph gl);
00083 glyph ver_flip   (glyph gl);
00084 glyph pos_rotate (glyph gl);
00085 glyph hor_extend (glyph gl, int pos, int by);
00086 glyph ver_extend (glyph gl, int pos, int by);
00087 
00088 /******************************************************************************
00089 * Abstract bitmap fonts and font metrics
00090 ******************************************************************************/
00091 
00092 struct font_metric_rep: rep<font_metric> {
00093   bool bad_font_metric; // when font metric could not be loaded
00094   font_metric_rep (string name);
00095   virtual ~font_metric_rep ();
00096   virtual metric& get (int char_code) = 0;
00097 };
00098 
00099 struct font_glyphs_rep: rep<font_glyphs> {
00100   bool bad_font_glyphs; // when font glyphs could not be loaded
00101   font_glyphs_rep (string name);
00102   virtual ~font_glyphs_rep ();
00103   virtual glyph& get (int char_code) = 0;
00104 };
00105 
00106 font_metric std_font_metric (string s, metric* fnm, int bc, int ec);
00107 font_glyphs std_font_glyphs (string name, glyph* fng, int bc, int ec);
00108 
00109 #endif // defined BITMAP_FONT_H