Back to index

texmacs  1.0.7.15
glyph.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : glyph.cpp
00004 * DESCRIPTION: glyphs of characters
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 #include "bitmap_font.hpp"
00013 
00014 #define PIXEL 256
00015 
00016 /******************************************************************************
00017 * Constructors and destructors for glyph
00018 ******************************************************************************/
00019 
00020 glyph_rep::glyph_rep (int w2, int h2, int xoff2, int yoff2,
00021                     int depth2, int status2)
00022 {
00023   depth   = depth2;
00024   width   = w2;
00025   height  = h2;
00026   xoff    = xoff2;
00027   yoff    = yoff2;
00028   lwidth  = w2;
00029   status  = status2;
00030 
00031   int i, n= (depth==1? (width*height+7)/8: width*height);
00032   raster= tm_new_array<QN> (n);
00033   for (i=0; i<n; i++) raster[i]=0;
00034 }
00035 
00036 glyph_rep::~glyph_rep () {
00037   tm_delete_array (raster);
00038 }
00039 
00040 glyph::glyph (int w2, int h2, int xoff2, int yoff2, int depth2, int status2) {
00041   rep= tm_new<glyph_rep> (w2, h2, xoff2, yoff2, depth2, status2);
00042 }
00043 
00044 /******************************************************************************
00045 * Getting and setting pixels
00046 ******************************************************************************/
00047 
00048 int
00049 glyph_rep::get_x (int i, int j) {
00050   if ((i<0) || (i>=width))  return 0;
00051   if ((j<0) || (j>=height)) return 0;
00052   if (depth==1) {
00053     int bit= j*width+i;
00054     return (raster[bit>>3] >> (bit&7)) & 1;
00055   }
00056   else return raster[j*width+i];
00057 }
00058 
00059 void
00060 glyph_rep::set_x (int i, int j, int with) {
00061   if ((i<0) || (i>=width)) FAILED ("bad x-index");
00062   if ((j<0) || (j>=height)) FAILED ("bad y-index");
00063   if (depth==1) {
00064     int bit= j*width+i;
00065     if (with==0) raster[bit>>3] &= ~(1 << (bit&7));
00066     else raster[bit>>3] |= (1 << (bit&7));
00067   }
00068   else raster [j*width+ i]= with;
00069 }
00070 
00071 int
00072 glyph_rep::get (int i, int j) {
00073   return get_x (i+xoff, yoff-j);
00074 }
00075 
00076 void
00077 glyph_rep::set (int i, int j, int with) {
00078   set_x (i+xoff, yoff-j, with);
00079 }
00080 
00081 /******************************************************************************
00082 * Adjusting top and bottom lines for extensible characters
00083 ******************************************************************************/
00084 
00085 void
00086 glyph_rep::adjust_bot () {
00087   int i;
00088   if (height<=2) return;
00089   for (i=0; i<width; i++) set_x (i, height-1, get_x (i, height-2));
00090 }
00091 
00092 void
00093 glyph_rep::adjust_top () {
00094   int i;
00095   if (height<=2) return;
00096   for (i=0; i<width; i++) set_x (i, 0, get_x (i, 1));
00097 }
00098 
00099 /******************************************************************************
00100 * Text output
00101 ******************************************************************************/
00102 
00103 tm_ostream&
00104 operator << (tm_ostream& out, glyph gl) {
00105   int i, j;
00106   out << "Size  : (" << gl->width << ", " << gl->height << ")\n";
00107   out << "Offset: (" << gl->xoff << ", " << gl->yoff << ")\n";
00108   for (i=0; i<gl->width+2; i++) out << "-";
00109   out << "\n";
00110   for (j=0; j<gl->height; j++) {
00111     out << "|";
00112     for (i=0; i<gl->width; i++) {
00113       int k= gl->get_x (i, j);
00114       if (k==0) out << " ";
00115       else if (gl->depth==1) out << "*";
00116       else if (k <= 9) out << k;
00117       else out << ((char) (55+k));
00118     }
00119     out << "|\n";
00120   }
00121   for (i=0; i<gl->width+2; i++) out << "-";
00122   out << "\n";
00123   return out;
00124 }