Back to index

texmacs  1.0.7.15
glyph_ops.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : glyph_ops.cpp
00004 * DESCRIPTION: operation on glyphs
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 #include "renderer.hpp"
00014 
00015 glyph
00016 join (glyph gl1, glyph gl2) {
00017   int x1= min (-gl1->xoff, -gl2->xoff);
00018   int y1= min (gl1->yoff- gl1->height, gl2->yoff- gl2->height);
00019   int x2= max (gl1->width- gl1->xoff, gl2->width- gl2->xoff);
00020   int y2= max (gl1->yoff, gl2->yoff);
00021   glyph bmr (x2-x1, y2-y1, -x1, y2, max (gl1->depth, gl2->depth));
00022 
00023   int i, j, dx, dy;
00024   dx= -gl1->xoff- x1, dy= y2- gl1->yoff;
00025   for (j=0; j<gl1->height; j++)
00026     for (i=0; i<gl1->width; i++)
00027       bmr->set_x (i+dx, j+dy, gl1->get_x (i, j));
00028 
00029   dx= -gl2->xoff- x1; dy= y2- gl2->yoff;
00030   for (j=0; j<gl2->height; j++)
00031     for (i=0; i<gl2->width; i++)
00032       bmr->set_x (i+dx, j+dy,
00033                 max (bmr->get_x (i+dx, j+dy), gl2->get_x (i, j)));
00034 
00035   return bmr;
00036 }
00037 
00038 glyph
00039 move (glyph gl, SI x, SI y) {
00040   x += PIXEL/2; y += PIXEL/2; abs_round (x, y);
00041   int xx= x/PIXEL, yy= y/PIXEL;
00042   int ww= gl->width, hh= gl->height;
00043   glyph bmr (ww, hh, gl->xoff- xx, gl->yoff+ yy, gl->depth);
00044 
00045   int i, j;
00046   for (j=0; j<hh; j++)
00047     for (i=0; i<ww; i++)
00048       bmr->set_x (i, j, gl->get_x (i, j));
00049   bmr->lwidth= gl->lwidth;
00050   return bmr;
00051 }
00052 
00053 glyph
00054 clip (glyph gl, SI x1, SI y1, SI x2, SI y2) {
00055   abs_round (x1, y1);
00056   abs_round (x2, y2);
00057   x1= x1/PIXEL; y1= y1/PIXEL;
00058   x2= x2/PIXEL; y2= y2/PIXEL;
00059   int i, j;
00060   int ww= gl->width, hh= gl->height;
00061   glyph bmr (ww, hh, gl->xoff, gl->yoff, gl->depth);
00062   for (j=0; j<hh; j++)
00063     for (i=0; i<ww; i++) {
00064       bool x_ok= (i+gl->xoff >= x1) && (i+gl->xoff < x2);
00065       bool y_ok= (gl->yoff-j >= y1) && (gl->yoff-j < y2);
00066       bmr->set_x (i, j, x_ok && y_ok? gl->get_x (i, j): 0);
00067     }
00068   return bmr;
00069 }
00070 
00071 glyph
00072 hor_flip (glyph gl) {
00073   int i, j;
00074   int ww= gl->width, hh= gl->height;
00075   glyph bmr (ww, hh, gl->xoff, gl->yoff, gl->depth);
00076   for (j=0; j<hh; j++)
00077     for (i=0; i<ww; i++)
00078       bmr->set_x (ww-1-i, j, gl->get_x (i, j));
00079   bmr->lwidth= gl->lwidth;
00080   return bmr;
00081 }
00082 
00083 glyph
00084 ver_flip (glyph gl) {
00085   int i, j;
00086   int ww= gl->width, hh= gl->height;
00087   glyph bmr (ww, hh, gl->xoff, gl->yoff, gl->depth);
00088   for (j=0; j<hh; j++)
00089     for (i=0; i<ww; i++)
00090       bmr->set_x (i, hh-1-j, gl->get_x (i, j));
00091   bmr->lwidth= gl->lwidth;
00092   return bmr;
00093 }
00094 
00095 glyph
00096 pos_rotate (glyph gl) {
00097   int i, j;
00098   int ww= gl->width, hh= gl->height;
00099   glyph bmr (hh, ww, gl->yoff, gl->width- gl->xoff, gl->depth);
00100   for (j=0; j<hh; j++)
00101     for (i=0; i<ww; i++)
00102       bmr->set_x (j, ww-1-i, gl->get_x (i, j));
00103   return bmr;
00104 }
00105 
00106 glyph
00107 hor_extend (glyph gl, int pos, int by) {
00108   int i, j;
00109   int ww= gl->width, hh= gl->height;
00110   bool ok= false;
00111   while (!ok) { // hack for corrupted pfb translations
00112     for (j=0; j<hh; j++)
00113       ok= ok || (gl->get_x (pos, j) != 0);
00114     if (!ok) pos += (pos < (ww>>1)? 1: -1);
00115     if (pos >= (ww>>2) && pos < (3*ww>>2)) break;
00116   }
00117   glyph bmr (ww+ by, hh, gl->xoff, gl->yoff, gl->depth);
00118   for (j=0; j<hh; j++)
00119     for (i=0; i<(ww+by); i++)
00120       bmr->set_x (i, j, gl->get_x (i<pos? i: (i<pos+by? pos: i-by), j));
00121   return bmr;
00122 }
00123 
00124 glyph
00125 ver_extend (glyph gl, int pos, int by) {
00126   int i, j;
00127   int ww= gl->width, hh= gl->height;
00128   glyph bmr (ww, hh+by, gl->xoff, gl->yoff, gl->depth);
00129   for (j=0; j<(hh+by); j++)
00130     for (i=0; i<ww; i++)
00131       bmr->set_x (i, j, gl->get_x (i, j<pos? j: (j<pos+by? pos: j-by)));
00132   return bmr;
00133 }